Introduction to UNIX for Web Developers Compression and Archiving Before we conclude this tutorial, there is one final subject that you should know about. This is compression/ archiving. UNIX provide several good tools for compressing and archiving your files so that you can create backups of important files or so that you can easily transfer large directory structures from one site to another. Though there are several good utilities for these purposes, two utilities have become the standard for web developers; partly because of their functionality and partly because they work cross-platform. That is, what is compressed and archived on unix can be decompressed and de-archived on Windows or Mac using such applications as WinZip or MacTar.

We'll look at the tar utility first.

The tar utility is used to archive an entire directory structure into a single file. this single file will contain all of the information in all of the directories. A tar file is easily moved from one site to another because it is a single file. when the tar file gets to the new location, you can unarchive the whole thing and the directory structure will be recreated in the new location. the tar command is executed as follows:

tar [key] [argument] [drive] [options] file_list

Tar has several options. The ones you probably will use are shown below

Option Explanation
key Specifies the action to take. Keys will be one of the following:
c = creates a new archive or overwrites an existing one
r = appends the files in the file_list to the end of an existing archive.
t = lists the contents of the archive
u = updates the archive with the latest copies of files within the archive.
x = extracts the files from the archive.
argument For your uses you will rarely need the argument but it is here if you do.
drive You will never need this option as a web technician. This is mainly used for sysadmins making global backups
f An option that specifies the name to be used for the archive.
A Makes all absolute file names into relative filenames.
v Tells tar to report in verbose mode about its activities
w Tells tar to query you for a "y" or "n" as it takes actions

Let's look at an example:


"compress" and "uncompress", on the other hand, are common utilities used for compressing files. They are particularly useful when used in combination with tar because once you tar an archive, you can compress the tar file which makes it much more portable (perhaps via ftp).

Take a look at the following example in which we use compress to shrink a TAR file:

Previous | Table of Contents