Therefore, to archive a group of files and compress the result, you can use the commands:
#tar cvf backup.tar /etcThe result will be backup.tar.gz. To unpack this file, use the reverse set of commands:
#gzip -9 backup.tar
#gunzip backup.tar.gzOf course always make sure that you are in the correct directory before unpacking a tar file.
#tar xvf backup.tar
You can use some UNIX cleverness to do all of this on one command line, as in the following:
#tar cvf - /etcHere, we are sending the tar file to ``-'', which stands for tar's standard output. This is piped to gzip, which compresses the incoming tar file, and the result is saved in backup.tar.gz.gzip -9c > backup.tar.gz
The -c option to gzip tells gzip to send its output to stdout, which is redirected to backup.tar.gz.
A single command used to unpack this archive would be:
#gunzip -c backup.tar.gzAgain, gunzip uncompresses the contents of backup.tar.gz and sends the resulting tar file to stdout. This is piped to tar, which reads ``-'', this time referring to tar's standard input.tar xvf -
Happily, the tar command also includes the -z option to automatically compress/uncompress files on the fly. However, it does this as per the compress algorithm-it does not use gzip. (Please note that the newest versions of GNU tar do in fact use gzip when using the -z option. However, if you use a tar binary from the Stone Age, like me, then don't expect -z to use gzip compression.)
For example, the command
#tar cvfz backup.tar.Z /etcis equivalent to
#tar cvf backup.tar /etcJust as the command
#compress backup.tar
#tar xvfz backup.tar.Zmay be used instead of
#uncompress backup.tar.Z
#tar xvf backup.tar
Refer to the man pages for tar and gzip for more information.