Search:  
Gentoo Wiki

HOWTO_File_Compression

This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc

Contents

Reasons for compression

There are many reasons to compress a file or a group of files on your computer. The primary reason for most people to compress files is for backing up their files or their whole system. Compressed files are also used to make downloads easier with decreased file size and combining several smaller files into one archive. By compressing files you save space on your hard drive and allow you store for more.

Types of compression

There are three main types of file compression on Linux computers. The most commonly used are tar, bzip, and gunzip. The most commonly used would have to be tar, then bzip and finally gunzip (gzip) coming in last.

Using tar

To decompress a standard tar archive file

tar -xvf foo.tar

To decompress a tar archive

tar -xzf foo.tar.gz

In order to decompress a tar archive with bzip compression

tar -xvjf foo.tar.bz2

Using bzip

The first thing you'll probably want to do is decompress an archive you've downloaded from somewhere on the web. Odds are you'll be downloading a bzip compressed tar archive.

bzcat foo.tar.bz2 | tar -xvf -

The second most commonly used command would be compressing your files into a bzip compressed tar archive.

tar -cvf - file | bzip2 > archivefile.tar.bz2

In order to compress more than one file into your archive simply extend the command.

tar -cvf - file1 file2 | bzip2 > archivefile.tar.bz2

Finally it also possible to compress your tar archive without a pipeline

tar -cvjf archivefile.tar.bz2 file-list

Using gunzip

The most basic way to use gzip is

gzip -c file1 file2 > foo.gz

You can also compress compressed files resulting in even higher compression

gzip -cd old.gz | gzip > new.gz

Finally if you'd like to decompress the zipped archive

gzip -d foo.gz

Using zip

To compress a group of files into .zip archive

zip foo.zip file1 file2 

To decompress a zipped archive simply

unzip foo.zip

Links

References

Wikipedia Article - Zip

Wikipedia Article - Gzip

Wikipedia Article - Bzip2

Wikipedia Article - Tar

Retrieved from "http://www.gentoo-wiki.info/HOWTO_File_Compression"

Last modified: Wed, 16 Jan 2008 08:09:00 +0000 Hits: 8,117