Tar and Gzip When Low On Disk Space

Anyone who knows me knows how I feel about AIX :-P.  One of my peeves is that out of the box, I cannot tar/gzip a directory with the “tar -cvz” command without breaking it up into two separate tar/gzip commands.

Every once in a while, you need to pull a large directory off your server to your local machine or just to copy it to another server.  Sometimes it’s easy just to copy the entire directory uncompressed.  Other times, it just makes sense to tar and gzip the directory so that the file that you are transferring is in a single archive and is compressed as to shorten the transfer time.

The problem with the tar/gzip option is that if you tar then gzip, you need the disk space to do so.

On AIX, here is a solution that will allow you to send what you tar to stdout then gzip it on stdin with no problems with disk space unless the gzip’d tar is still bigger than the diskspace you have available.  This *should* work on other *NIX systems that you cannot throw the gzip switch in the tar command.

tar -cvf - /path/to/dir/you/want/to/tar | gzip > /destination/for/gzip'd/tar.tgz-boogybren