The tar utility is a great utility for creating backups. However, by default it will not compress the backup. If you want to compress the backups you make with tar, you can choose from three options:
-z: This compresses the backup with the gzip utility. This utility offers a great balance between speed and compression ratio.
-Z: This uses the zip utility. Speed is good, but the compression ratio is not optimal.
-j: This uses the bzip2 utility. This utility compresses about 10 percent more than gzip but takes considerably longer to complete.
You can use all of these compression utilities from the tar command line. As an alternative, it is possible to use them as separate commands. Therefore, you have two ways to create a compressed archive with tar; tar -czvf /usr.tar.gz /usr will make a complete archive of the /usr directory and compress that with gzip. Alternatively, first use tar -cvf /usr.tar /usr and then compress the resulting archive with gzip.
Using gzip isn't hard; just call the utility followed by the name of the file you want to compress. For example, use gzip somefile. Uncompressing a file that is compressed with gzip isn't hard either; for that purpose you can use the gunzip utility. For example, gunzip somefile will uncompress the file you have just compressed by using gzip. Instead of gzip and gunzip, you can also use bzip2 and bunzip2. They work the same as gzip and gunzip, but the name of the command is different.
Was this article helpful?