3.4. Handling compressed files (tarballs)[29]

The tar utility (tar is short for tape archive) allows you to compress files and directories into a single file called a tarball. Note that compressing, listing, and extracting all use the same command (tar), but the options used differ depending on which action you wish to perform.

Like with all commands, you can find more information by checking man tar, but since the version of tar used on Linux is a GNU product, you can also find information by typing info tar.

Table 3.4. Commands for handling compressed files (tarballs)[30]

CommandAction

tar -czf foo.tar.gz file_list

Creates a tarball called foo.tar.gz from the list of files and directories (separated by spaces) in file_list

tar -tzf foo.tar.gz

Lists the files and directories in foo.tar.gz (does not extract them)

tar -xzf foo.tar.gz

Extracts the contents of foo.tar.gz and places them in the current directory

[30] Although, when used with the options above, tar will be silent (that is, it won't provide any message to the user unless there's a problem, as mentioned in Section 1.5, “Key differences between Windows/Mac OS X and Linux”), you can use the -v option for verbose output, as in tar -czvf or tar -xzvf; when used as tar -tzvf, a “long listing” output like that in ls -l is used.




[29] Joe Barr, CLI for Noobies: A Primer on the Linux Command Line (Boston: Prentice Hall, 2008), 151-155.


Back to Guide main page