November 11, 2004

BZipping Directories using Tar

Just a quick note before I forget on how to run bzip2 and compress a directory structure using the tar utility. Actually what it really does is pass the directory structure through tar to bzip2 which compresses it and writes it to a file.

tar -cf - dir | bzip2 -c9 > /destination/path/filename.tar.bz2

the '-' tells tar to write to stdout (so instead of writing to the disk, it writes to the pipe (|)

then bzip2 takes the input, compresses it, and writes it to stdout again (that is what the -c parameter does).

The shell sees > and redirects all of the output into the file specified.

Nothing hits the disk until '>'

Final Notes: the 9 parameter to the bzip2 file tells it to compress it as much as possible. This is up to you, 0 is the least CPU intensive and lowest compression, while 9 is the most CPU intensive and gives the highest compression.

Posted by ultrabob at 02:12 PM | Comments (0)