Working with tar, gz and bz2 files
Originally Posted by Ned Slider
Additional contributions by Spankin Partier
Tar files (sometimes called tarballs) are the Linux equivalent of Window's zip files except that they're not compressed. The tar (Tape Archiver) program is a really old UNIX command line utility originally developed for backing up to tape, but is still widely used today for the distribution of files in the Linux world. When compresion is required, the tar archive is subsequently compressed using either gzip or bzip2. Filenames will typically end in .tar, .tar.gz (or .tgz) or .tar.bz2 depending if they are uncompressed or compressed using gzip or bzip2, respectively. If you are creating very large archives, gzip is generally considered faster and bzip2 generally considered to offer better compression.
Sooner or later you'll probably come across a tar file and will need to extract it. Here are the commands for extracting common tar formats:
Code:
tar xvf tarfile.tar
tar xvzf tarfile.tar.gz
tar xvjf tarfile.tar.bz2
The switches are extract (x), verbose (v), gzipped (z), bzip2 (j) and filename (f). The function or operation to be performed, in this case extract (x), is usually the first switch and the f switch usually comes at the end and is immediately followed by the filename.
Tar files can be similarly created using the create (c) switch in place of extract (x). Here's how we would create a tarfile of the contents of the /home/ned/temp directory, either as an uncompressed archive, or compressed using gzip or bzip2, respectively:
Code:
tar cvf tarfile.tar /home/ned/temp
tar cvzf tarfile.tar.gz /home/ned/temp
tar cvjf tarfile.tar.bz2 /home/ned/temp
Now you know the difficult way to work with tar archives, we'll tell you the easy way. For KDE users, right clicking a tar archive and selecting open with archiving tool will open the file in Ark, the KDE equivalent of WinZip. From there you can extract your archive. (Perhaps a gnome user could provide details of a similar process in gnome). Alternatively, simply double clicking on a tar archive in KDE or konqueror will open the archive.
As a side note, WinZip also supports tar and tar.gz files so you can share your tar files with Windows users too.
..