Unix File Compression and Archiving FAQ 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. Archiving Q: How do I untar foo.tar? A: tar x -f foo.tar (x is for extract, f is for filename) Q: How do I create a tarfile from a directory? A: tar c -f foo.tar foo/ (c is for create) Compression Q: How do I uncompress foo.gz? A: gunzip foo.gz Q: And compress a file to .gz? A: gzip foo Q: How do I uncompress foo.bz2? A: bunzip2 foo.bz2 Q: And compress a file to a .bz2? A: bzip2 foo (sensing a pattern here?) Q: and what about .zip? A: unzip foo.zip A: zip foo (yes, it really is this simple) ** 'unzip' can uncompress win32 self-extracting .exe files!! Q: .Z files? A: uncompress foo.Z A: compress foo.Z Putting them together Q: How do I uncompress foo.tar.gz? A: gunzip foo.tar.gz; tar x -f foo.tar A: gunzip < foo.tar.gz | tar x -f - A: tar x -z -f foo.tar.gz (z tells tar to use gunzip) A: tar x -zf foo.tar.gz A: tar xzf foo.tar.gz (the f option must be last) A: tar xzvf foo.tar.gz (v lists every file as it untars, it's "verbose") Q: How do I uncompress foo.tar.bz2? A: bunzip2 foo.tar.bz2; tar x -f foo.tar A: bunzip2 < foo.tar.bz2 | tar x -f - A: tar x -jf foo.tar.bz2 (j tells tar to use bunzip2 ("b" was already taken)) A: tar xjf foo.tar.bz2 A: tar xjvf foo.tar.bz2 ** different versions of tar may use j, I, or y More Information Q: Why 4 different compression programs? A: "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. Q: How can I move lots of directories and files and preserve them perfectly? A: cd /source/directory; tar cf - . | tar xf - -C /destination/directory