You will encounter various forms of archives, compressed and uncompressed, when working in the shell. Below are examples of how to uncompress files with the extensions .tar, .tar.gz, and .tar.bz2. It is easy to create a tar archive (a tarball) and examples are given. For gzip and zip archives I only outlined how to uncompress them.

tar Archives

tar xvf foo.tar
## unpacks the archive foo.tar
tar xvfz foo.tar.gz
## unpacks and uncompresses the compressed archive foo.tar.gz
tar cvzf foo.tar.gz foo1.txt foo2.txt
## compresses and archives the files foo1.txt and foo2.txt into foo.tar.gz
tar cvzf foo.tar.gz dir1 dir2
## same as above but applied to the directories dir1 and dir2
tar xvfj foo.tar.bz2
## sometimes tar archives come compressed using bzip2
## this is how you uncompress these archives
You may sometimes see a tar archive with a .tgz extension. This is equivalent to a tar.gz extension and should be treated identically.

To look at the files in a tar archive without uncompressing use:
tar -tf yourfile.tar

gzip Archives

gunzip foo.gz
## uncompresses the gzip archive foo.gz
gzip foo.tar
## compress foo.tar -- results in foo.tar.gz

zip Archives

## uncompresses