Long before utilities such as StuffIt and Zip existedlong before the Mac existed, in fact!Unix users could group files together into
archives and compress the archives to take up less disk space, which was vastly more expensive then. Unix offers several archiving and compression tools:
tar (short for
t ape
ar chive) was originally used to combine a collection of files into a single file, which was written to tape. But you don't have to write the file to tape; you can write it to any device your Unix system knows about: disks, tapes, CD-Rs, even Terminal.
compress and uncompress do what you probably expect them to: compress and expand files. Text files are very compressible, sometimes 10 to 1. Files that have already been compressed such as JPEG and MPEG files and QuickTime movies, however, can actually become larger.
gzip is a newer set of utilities that are like compress and uncompress on steroids. gzip includes more options and offers better compression ratios.
You can learn more about these commands by viewing their man pages. In the Terminal window, type man tar, man compress, man uncompress, or man gzip and press
It's useful to know something about these tools because you will encounter them if you download software from Internet archives.
Type tar [-cxtvpf] [-C
directory ]
archive file … and press
Table 2 for tar options.)
Option | Description |
|---|---|
-c | Creates a new archive |
-x | Extracts files from the named archive |
-t | Displays a list of files and directories in the named archive |
-v | Verbose mode: Tells you everything tar is doing |
-p | Preserves permissions, owners, and modification dates if possible |
-f | Archives files to the following filename or extracts files from the following archive name |
-C | Puts extracted files in the specified location |
Here are some examples using the tar command:
tar -cf archive.tar file1 directory1 file2 creates and then writes to the archive named
archive.tar: file1, directory1 and all its contents, and
file2 in that order.
tar -tvf old-archive.tar displays everything in the archive called
old-archive.tar but does not extract anything. The t option just prints the contents of a tar archive.
tar -xpvf old-archive.tar exTRacts the files and directories in the archive file called
old-archive.tar and puts the resulting files in the current directory. The v option reports progress and the p option preserves the ownerships and modification dates of the original files. (The tar file is unaffected and remains on the disk.)
tar -xpvf old-archive.tar -C /usr/local/src exTRacts the files and directories in the archive file called
old-archive.tar and puts the resulting files in the directory
/usr/local/src .
It's a standard procedure to end archive names with a .tar suffix, and you should honor this standard to keep evil spirits out of your computer.
Type compress
file ... (for example, compress file.txt), and press
Or
Type uncompress
file ... (for example, uncompress file.z), and press
Your original file is removed if either of the commands successfully complete the compression or decompression.
By convention, compressed files should have a .Z extension. The compress command will automatically append this extension to the filename.
Type gzip
file ... and press
Or
Type gunzip
file ... and press
The gzip command has several options. The r option, for recursive, goes into specified subdirectories and compresses or uncompresses the files. The v option, for verbose, tells the command to report its progress.
zcat file lists the contents of a compressed file to Terminal (or pipes the content to another command) without altering the original archive.