(Un)compressing directories

in Linux, filesystem, tar

For all (well most) of your console compressing / uncompressing needs, tar is there. All you need to do is set it to work.

It is interesting to note that compression in linux is a two stage process: files are first serialized into one stream using tar (whose initial use was serialization for tape storage), and then the stream is compressed using a library such as zip or bzip

Uncompressing a file

Assuming you downloaded a compressed file, you only need to run

# tar zxvf mycompressedfile.tar.gz

Where z is for .tar.gz files, and can be replaced with j for .tar.bz2 or even completely omitted for simple .tar files.

Note that tar always uses the current directory as a target ( where your files are extracted ), so you should change directory to where you want your files to be extracted, and then run tar using a path to the compressed file.

Compressing a whole directory

To compress an entire directory to a single compressed file, just use

# tar czfv outputfilename.tar.gz sourcedirectory/

Where z is for .tar.gz files, and can be replaced with j for .tar.bz2 or even completely omitted for simple .tar files.

If you want to just tar a file instead of a directory just use the same syntax and point it to the source file.