Tarball Etiquette

Creating a tarball the proper way is very, very easy. First, let's consider what is expected of a tarball. For example:

netgeek ~% ls -F
bin/ share/ foo-0.91.tar
netgeek ~% tar -xf foo-0.91.tar
netgeek ~% ls -F
bin/ share/ foo-0.91/ foo-0.91.tar
netgeek ~% ls -F foo-0.91
bar barney baz foo

As you can see, the tarball creates a directory named after itself and placed all its files in that directory. It does not just unpack the files into the current working directory.

Create A Subdirectory

Your tarball is one of many. To distinguish your files from other, surrounding files, create a directory to place all the files in. For consistency, name the directory after the tarball.

Do Not Include .

A fast way of removing all files that any tarball unpacks is tar -tf foo.tar | xargs rm -rf . This is: list all the files contained in the tarball, then delete each (if it's a directory, delete everything in the directory). Under a Unix-like filesystem . is another name for the current working directory. So, if the tarball contains . that means that command will delete the current directory and everything below it. This is not good — do not do it!

The Right Way

Let us assume you have a bunch of files pertaining to the fourth edition of the book DNS And Bind. They would be stored in a directory named dns_and_bind-4. To make the tarball, named dns_and_bind-4.tar.gz, run

tar -zcf dns_and_bind-4.tar.gz dns_and_bind

The z gzips the tarball, the c tells it to create a tarball, and f is followed by the file to work on — in this case, the output file.

Retrospective,

This was copied to the new site.

Home - Contents - Search

Mike Burns <mike@mike-burns.com>