Archived+and+Compressed+Files

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= code format="bash" tar xvf foo.tar tar xvfz foo.tar.gz tar cvzf foo.tar.gz foo1.txt foo2.txt tar cvzf foo.tar.gz dir1 dir2 tar xvfj foo.tar.bz2 code You may sometimes see a tar archive with a .tgz extension. This is equivalent to a tar.gz extension and should be treated identically.
 * 1) unpacks the archive foo.tar
 * 1) unpacks and uncompresses the compressed archive foo.tar.gz
 * 1) compresses and archives the files foo1.txt and foo2.txt into foo.tar.gz
 * 1) same as above but applied to the directories dir1 and dir2
 * 1) sometimes tar archives come compressed using bzip2
 * 2) this is how you uncompress these archives

To look at the files in a tar archive without uncompressing use: code format="bash" tar -tf yourfile.tar code =gzip Archives= code format="bash" gunzip foo.gz gzip foo.tar code =**zip Archives**= code format="bash" unzip foo.zip code
 * 1) uncompresses the gzip archive foo.gz
 * 1) compress foo.tar -- results in foo.tar.gz
 * 1) uncompresses foo.zip