Installation guide

128 Chapter 12. Managing Files and Directories
Tip
For more information, type man zip and man unzip at a shell prompt to read the man pages for zip
and unzip.
12.3.2. File Archiving
A tar file is a collection of several files and/or directories in one file. This is a good way to create
backups and archives.
Some of the options used with the tar are:
-c — create a new archive.
-f when used with the -c option, use the filename specified for the creation of the tar file;
when used with the -x option, unarchive the specified file.
-t — show the list of files in the tar file.
-v — show the progress of the files being archived.
-x — extract files from an archive.
-z — compress the tar file with gzip.
-j — compress the tar file with bzip2.
To create a tar file, type:
tar -cvf filename.tar files/directories
In this example, filename.tar represents the file you are creating and files/directories rep-
resents the files or directories you want to put in the archived file.
You can tar multiple files and directories at the same time by listing them with a space between each
one:
tar -cvf filename.tar /home/mine/work /home/mine/school
The above command would place all the files in the work and the school subdirectories of
/home/mine in a new file called filename.tar in the current directory.
To list the contents of a tar file, type:
tar -tvf filename.tar
To extract the contents of a tar file, type:
tar -xvf filename.tar
This command does not remove the tar file, but it places copies of its contents in the current working
directory.
Remember, the tar command does not compress the files by default. To create a tarred and bzipped
compressed file, use the -j option:
tar -cjvf filename.tbz
tar files compressed with bzip2 are conventionally given the extension .tbz.