tar is an archiving program and it doesn’t compress files.
gzip (.gz), bzip2 (.bz2) and xz(.xz) are all data compression tools and they don’t archive files.
To do what people do with WinRAR and 7-Zip, people usually use tar along with one of the data compression tools mentioned above to created compressed archives (.tar.gz, .tar.xz, or .tar.bz2).
To use tar along with these compression tools, you pass options to tar, like
tar abcd file
Despite its staggering man page, I usually use only three or four options. Some of them include:
- a is optional and specifies the compression tool, z for gzip, j for bz2 and J for xz
- b specify the desired operation, c for create, x for extract and t for inspect (table)
- c is optional and toggle the verbose mode, v for on
- d is optional and tells tar that you are going to provide a filename, f for on
And here are some examples of tar:
- Decompressing and extract all the files in a .tar.gz file: tar zxvf a.tar.gz
- Archive and compress multiple files using tar and xz: tar Jcvf ar.tar.xz *.log
- The command above is the same as: tar cvf ar.tar *.log; gzip ar.tar
- Inspect the content of a compressed archive file: tar Jtvf ar.tar.xz
UPDATE:
A better way to memorize these commands would be
tar xzf a.tar.gz
# extract a gzip filetar xJf a.tar.gz
# extract a xz file# btw, if you want to put the extracted files into a new directory
tar -C directory xzf a.tar.gz