• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 4. Unix Security & Utilities > Archive & Compression Utilities

Archive & Compression Utilities

Long before utilities such as StuffIt existed— long 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 tape archive) 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-RWs, even the 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 to view the command's man pages.

  • Experienced Unix users often use tar and gzip together to produce a compressed archive with a name like file.tar.gz or file.tgz. A useful way to uncompress and untar a file uses pipes. For example, gzcat file.tar.gz I tar xf - uncompresses the gzipped file and pipes the output to the tar command for extraction. The - in the tar command is necessary to tell tar to expect its input from the pipe (its standard input device).

  • These tools are useful to know something about because you will encounter them if you download software from Internet archives. If you don't need the GUI interface of StuffIt, the tar/gzip utilities will do the same job for free!

To create an archive from an entire directory tree

Type tar [-cxtvpf] [-C directory] archive file and press . (Consult Table 1 for tar options.)

Table 1. tar Options
-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 me everything you are 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.

To compress & decompress with compress & uncompress

Type compress file ... (for example, compress file.txt), and press .


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.

To compress or decompress with gzip & ungzip

Type gzip file ... and press . This compresses the files, adds the .gz suffix to their names, and removes the original files.


Type ungzip file ... and press . This uncompresses the files and removes the original archive.


  • 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 the Terminal (or pipes the content to another command) without altering the original archive.

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint