Unix for Mac OS X 10.4 Tiger: Visual QuickPro Guide (2nd Edition)

File Compression and Archiving

If you've been using a Mac, you have most likely seen files compressed using StuffIt, Aladdin Systems' popular file-compression utility.

In the Unix world there are a handful of commands, already part of the operating system, that are used for archiving and compressing files. It's likely that command-line software you download from the Internet will be compressed using these tools.

gzip

gzip is a program for compressing files. The g in gzip is from GNU (see the sidebar "What Is a GNU?"), and the zip is a reference to an earlier program called zip . gzip is not the same as zip , though. The older zip program not only compresses files, but it also combines multiple files and/or directories into a single file. The gzip program is more widely used than zip in the Unix world because gzip provides better compression (smaller files), and the Unix tar command is the commonly used program to combine multiple files into a single file. (The version of tar on Mac OS X can also compress its output with gzip . See tar below.)

To compress a file using gzip:

Tips

gunzip

Of course, once you have a compressed file, you'll want to know how to uncompress it.

To uncompress a gzipped file:

Tips

What Is a GNU?

GNU is a recursive acronym (an acronym that refers to itself) that stands for Gnu's Not Unix . The GNU project is the domain of the Free Software Foundation, which coordinates a huge volunteer effort to create a complete Unix-like operating system that has the following four freedoms:

  • Freedom to run the program, for any reason

  • Freedom to study the internal workings of the program, and to alter them to suit you

  • Freedom to redistribute copies so that you can help other people

  • Freedom to make the program better, and make your changes available to the public, so that the others benefit from your efforts

There are hundreds of GNU software packages. There is even a GNU-Darwin project: the GNU-Darwin Distribution (http://gnu-darwin. sourceforge .net).

There's more information on the GNU project and the Free Software Foundation at GNU's Not Unix! (www.gnu.org).

tar

In many cases you will want to compress an entire directory (folder). Unlike the StuffIt program, gzip does not compress directories. To deal with this, you use another program from the command line, called tar , which creates a single file from a directory and all its contents (a tar file ). tar was originally used only for making backups to tape systems (hence its name, for tape archive ), but is now used far more frequently to combine entire folders into a single tar file prior to compression.

The version of tar included with Mac OS X can simultaneously combine a directory full of files into one file and compress the result with gzip .

To archive a directory using tar:

Tips

Of course, once you have a tar file, you want to be able to reverse the process and turn it back into a directory (this is called untarring or unpacking ).

To unpack a tar archive:

Категории