Section 11.6:File Compression and Archiving with Gzip, Zip, and Tar
11.6.2 Archiving with Tar
Tar files place several files or the contents of a directory or directories in one file. This is a good way
to create backups and archives. Usually, tar files end with the .tar extension.
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
represents the files or directories you want to put in the new file.
You can use absolute or relative pathnames for these files and directories . Separate the names of files
and directories with a space.
The following input would create a tar file using absolute pathnames:
tar -cvf foo.tar /home/mine/work /home/mine/school
The above command would place all the files in the /work subdirectory and the /school subdirectory
in a new file called foo.tar in the current working directory.
The command tar -cvf foo.tar file1.txt file2.txt file3.txt would place
file1.txt, file2.txt and file3.txt in a new file called foo.tar.
To list the contents of a tar file, type:
tar -tvf foo.tar
To extract the contents of a tar file, type:
tar -xvf foo.tar
This command does not remove the .tar file, but it places copies of the .tar contents in the current
working directory.
The tar command does not compress files automatically. You can compress tar files with:
tar -czvf foo.tar
Compressed tar files are conventionally given the extension .tgz and are compressed with gzip.
To expand a compressed tar file type:
tar -xzvf foo.tgz
131
Need help?
Do you have a question about the LINUX 7.2 and is the answer not in the manual?
Questions and answers