As part of my job, I often need to archive and retain copies of very large files for my clients. To help save disk space, I compress these files before they are archived. I could just use the same compression program for every file, but since different compression algorithms excel at dealing with different types of input, I find it’s much better to make use of a particularly useful shell script called bestcompress that I came across several years ago in Wicked Cool Shell Scripts by Dave Taylor. It compares the output sizes of files produced by three different compression programs available on most Unix implementations (including Mac OS X) when applied to the actual file a user needs to compress. After executing the script, the user is left with the smallest resultant compressed file produced by either compress, gzip, or bzip2.
The script is available on the book’s website, along with a detailed explanation of exactly how it works and how to use it.