
If you’re new to Linux and intent on peering under the hood a bit to see what makes things work, then you’ve probably encountered a range of files which are compressed in various formats. This guide is meant to be a quick and easy way to distinguish what’s what in compressed files. It’s written on and for Ubuntu but will be very useful for other distributions as well.
.gz, .tar.gz, .bz2, .zip – these are all files that have been compressed in one form or another. Compressed? There’s a real good technical explanation for what compression is and how the varying utilities achieve their end goal, but we’re not going to go into this here. Suffice it to say that compressing something is squishing it down to a smaller size so that it can be more easily stored or transported about. Uncompressing is doing the opposite so that we end up with the original, full sized file in the end.
Let’s look at some of the more common compression utilities and compressed files you’re likely to find in Linux.
The first thing we’re going to tackle is the tarball. This is one of the oldest and still widely used compression methods that was originally used to store data on tapes. Tar comes from Tape ARchive.
You’ll most likely encounter tarballs as tar.gz files, which is to say foo.tar.gz is a tarball. It could contain a single text file, or 3 Gigabytes worth of directories and files. Tar’d files are not really smaller than untar’d files, which is why they’re further compressed with a utility called Gzip – hence the .gz after the .tar. So foo.tar.gz has been set for archiving (tar) and then compressed (gzip). Another way of looking at it is that tar can take multiple files an make one big file out of them, then gzip squashes them down.
Once you’ve gotten yourself a tarball – perhaps you’ve downloaded a neat utility you want to install, what do you do with it? Most distros will allow you to right click on the tarball through the GUI and simply choose ‘extract here’. If you’re looking at it through a terminal session however, here’s what you want to do.
If you have a tarball called foo.tar.gz and you want to extract it, type:
tar zxvf foo.tar.gz
That will extract the tarball, preserving directory structures. Note also that .tgz files are the same thing as tar.gz just in a shorter written (or typed) format.
Want to make a tarball from a directory called bar containing the files foo1 and foo2?
tar -czvf foobar.tar.gz bar/
Let’s look a little closer at gzip, as it’s an easy to use utility. If you have a large file, say a 2 MB document called yowsa.txt that you want to compress, you could use gzip as follows:
gzip yowsa.txt
That would give you a file called yowsa.txt.gz To uncompress this file, type:
gzip -d yowsa.txt.gz
or
gunzip yowsa.txt.gz
And for bonus points, say you have a gzipped file called yowsa.txt.gz that you want to look at without uncompressing. Use the zcat program to do this. It functions much as cat, except on gzipped files.
zcat yowsa.txt.gz
The other file format you’re most likely to encounter in Linux-land is the .bz2 file, or stuff crunched up with Bzip2. This one’s pretty simple. If you have a file called foo.bz2 and you want to uncompress it:
bunzip2 foo.bz2
If you want to compress the file foo:
bzip2 foo
That will result in a file called foo.bz2. Remember that bzip2 compresses and bunzip2 expands. Why bzip2 and not just bzip? The same reason we have 7 Up and not just Up.
Last but not least, is the good old .zip file. This is a file that you’re just as likely to encounter in the Windows world as in the Linux world and it should look comfortably familiar. Except that you’ll be doing this in the command line!
If you have a file like foo.zip and you want to uncompress it:
unzip foo.zip
Say you want to make a zip file that’s also password protected:
zip -e foo.zip foo
Note that the name of the compressed file (foo.zip) comes first, then the file you wish to compress next.
As always there are a ton of other things you can do with these nifty little programs. Remember that the man command is your friend. Use it often, use it well.
geek out.
Popularity: 1% [?]












0 Comments For This Post
3 Trackbacks For This Post
October 3rd, 2006 at 10:34 pm
[...] If you’re new to Linux and intent on peering under the hood a bit to see what makes things work, then you’ve probably encountered a range of files which are compressed in various formats. This guide is meant to be a quick and easy way to distinguish what’s what in compressed files. It’s written on and for Ubuntu but will be very useful for other distributions as well. [...]
October 27th, 2006 at 12:40 am
[...] Page Summary: This is one of the oldest and still widely used compression methods that was originally used to store data on tapes. It could contain a single text file, or 3 Gigabytes worth of directories and files. This guide is meant to be a quick and easy way to distinguish what?s what in compressed files. It?s written on and for Ubuntu but will be very useful for other distributions as well.read more | digg story [...]
July 14th, 2007 at 11:19 pm
[...] way to distinguish what�s what in compressed files. read more | digg story Filed under: Tech [...]
Leave a Reply