## 39.3. GNU tar Sampler

Go to http://examples.oreilly.com/upt3 for more information on: tar

GNU tar has plenty of features; some people would say "too many." I don't agree. GNU tar has features I wish I'd had for years in more "standard" versions. This article lists my favorites. For a complete list, check the info documentation for tar.

- Section 15.7 describes how to compress an archive file you've created. If you're using GNU tar, this is even easier, since tar itself can do the compression. Simply use the z option when writing or reading archives. For example, to make the gzipped tar archive progs.tar.gz from all ".c" and ".h" files:

  >     % tar cvzf progs.tar.gz *.c *.h

  You can also use the long option - -gzip to get gzip compression, and the long option - -bzip2 to get bzip2 compression.

- I've made the classic mistake of archiving files with their absolute pathnames (Section 38.11). GNU tar saves you from that goof. It always stores absolute pathnames as relative paths unless you add the - -absolute-names option.

- Often I want to make a tape backup of my most recent work on a big project, but not all the thousands of files in a directory tree. The clumsy way to do that is by using find -mtime to make an include-file for the standard tar -I option. GNU tar to the rescue: its - -after-date option lets me tell it what directories to look in and how recently the files should have been changed.

- When I extract an archive, I may be writing into a directory that has other files. The - -keep-old-files option tells GNU tar not to overwrite existing files.

One caution about GNU tar: it creates ANSI-format tar archives. Extracting one of these archives with the old V7 tar can cause warning messages like "tar: unexpected EOF." But, of course, GNU tar has an option to create old-format archives: - -old-archive.

--JP and TOR

Copyright © 2003 O'Reilly & Associates. All rights reserved.