First, a little background. In Unix, compressing (making something smaller) and archiving (combining many things into one) are two different functions. Also, a .tgz file is the same as a .tar.gz file, and a .tbz is the same as a .tar.bz2 file.
The most commonly asked question about compression type programs
Why 4 different compression programs?
Compress is the standard legacy Unix compression program. gzip has been around for 2 generations of Unix users, it compresses better than compress, and everyone loves it. Then someone has to do better and create bzip2, which has significantly better compression ratios. However, bzip2 takes longer to work, and can be really slow on large files. And of course, zip is just for compatibility with windows users.
Decompressing Files
How do I decompress a .tar type file?
tar xf file.tar
How do I decompress a .gz type file?
gunzip file.gz
How do I decompress a .tar.gz type file?
gunzip file.tar.gz
How do I decompress a .bz2 type file?
bunzip2 file.bz2
How do I decompress a .tar.bz2 type file?
bunzip2 file.tar.bz2
How do I decompress a .zip type file?
unzip file.zip
unzip can decompress win32 self-extracting .exe files!!
How do I decompress a .Z type file?
uncompress file.Z
How do I decompress a .7z or .7za type file?
7za x newarchive.rar
How do I decompress a .rar type file?
unrar x newarchive.rar
Compressing Files
How do I create a .tar file of a directory/file?
tar cf file.tar file/
How do I create a .gz file of a certain directory/file?
gzip file
How do I create a .tar.gz file of a certain directory/file?
tar czspf file.tar.gz directory/ or file
How do I create a .bz2 file of a certain directory/file?
bzip2 file
How do I create a .tar.bz2 file of a certain directory/file?
tar cjspf file.tar.bz2 directory/ or file
How do I create a .zip file of a certain directory/file?
zip file (yes, it really is this simple)
How do I create a .Z file of a certain directory/file?
compress file.Z
How do I create a .7z or .7za file of a certain directory/file?
7za a newarchive.7z files*
For full command syntax and options run 7za without any parameters.
Note: 7za can also extract RAR archives.
How do I create a .rar file of a certain directory/file?
rar a newarchive.rar files*
For full command syntax run rar and unrar without any parameters.
Putting Them Together
Various other ways for decompressing a .tar.gz type file.
gunzip file.tar.gz; tar xf file.tar
gunzip < file.tar.gz | tar xf -
tar xzf file.tar.gz (z tells tar to use gunzip)
ar xzf file.tar.gz
tar xzf file.tar.gz (the f option must be last)
tar xzvf file.tar.gz (v lists every file as it untars, it's "verbose")
Various other ways for decompressing a .tar.bz2 type file.
bunzip2 file.tar.bz2; tar xf file.tar
bunzip2 < file.tar.bz2 | tar xf -
tar xjf file.tar.bz2 (j tells tar to use bunzip2 ("b" was already taken))
tar xjf file.tar.bz2
tar xjvf file.tar.bz2
different versions of tar may use j, I, or y
How can I move lots of directories and files and preserve them perfectly?
cd /source/directory; tar cf - . | tar xf - -C /destination/directory
