Computing Facilities
Electrical and Computer Engineering
Northwestern University

CFS Home | FAQs | Policies | PC Software | ECE Home | Search

Archiving and Compressing Files

To save hard disk space (and to keep under your disk quota), it is a good idea to archive and compress little-used subdirectories within your home directory. If you need to access a compressed directory later, you can restore it easily. This document explains how.

Creating a Compressed Archive

To archive and compress a directory and all its contents (including all subdirectories), type the following command at your UNIX system prompt.

tar cf - DIRNAME | gzip -v > DIRNAME.tar.gz

Here, DIRNAME is the name of the directory you wish to archive. This will create a compressed archive file called DIRNAME.tar.gz. This file contains all of the files in the original directory, but will typically occupy less than half of the disk space of the original.

Tip: GNU Tar (which is installed on ECEnet hosts) has the functionality of gzip built in via the -z flag. So a shorthand for the above command pipeline using GNU's tar is:

/meas/bin/tar zcf DIRNAME.tar.gz DIRNAME

If you are new to tar, then your next step should be to verify that the archive contains what you expect. The command

gunzip < DIRNAME.tar.gz | tar tvf -
GNU tar shorthand:  /meas/bin/tar ztvf DIRNAME.tar.gz

lists the contents of your archive. Inspect the results and confirm that all of your targetted files are there.

Now that you have a compressed copy of your little-used subdirectory, and verified the contents of the archive, you may remove the original directory and all of its contents:

rm -rf DIRNAME

Restoring Archived Files

The command for extracting all files and directories from DIRNAME.tar.gz is very similar to the commands for verifying the archive, except instead of using the -t flag, we use -x

gunzip < DIRNAME.tar.gz | tar xvpf -
GNU tar shorthand: /meas/bin/tar zxvpf DIRNAME.tar.gz

Note that we also use the -p flag. This tells tar to retain the same file permissions as the original in the archive. The directory DIRNAME will be created and restored to its original state. You can now remove the archive file with

rm DIRNAME.tar.gz

See the manual pages on tar(1), gzip(1), and GNU Tar for more information.

2145 Sheridan Road . Evanston / IL . 60208
Phone: 847-491-8140 . FAX: 847-491-4455
webmaster@ece.northwestern.edu

Copyright © 2003 Northwestern University § All rights reserved § Thu Oct 23 15:27:50 CDT 2003