Tape Archiver. A portable method to bundle up files and directories - even for transport to Windows, because Unzip understands tar formats (though it will loose permission and ownership information).
At one time, tar was an inferior choice for backup because it lacked many of the features of cpio (such as the ability to backup device files or empty direcories), but modern tars don't have those problems.
Tar (and cpio of course) can create its archive in an ordinary file:
tar cvf /tmp/myfile.tar .
archives the current directory to /tmp/myfile.tar. To unpack that somewhere else,
tar xvf /tmp/myfile.tar
It's not necessary to specify WHAT to unpack, though if you only wanted a specific file you could:
tar xvf /tmp/myfile.tar ./somedir/somefile
Before unpacking, it's often helpful to examine the tape or archive:
tar tvf /tmp/myfile.tar
will list the contents.
apl$ tar tvf this drwxr-xr-x apl/staff 0 2003-11-06 04:38:21 ./fp/ -rw-r--r-- apl/staff 0 2003-11-06 04:38:21 ./fp/1 -rw-r--r-- apl/staff 0 2003-11-06 04:38:21 ./fp/t
If I want that restored, I cannot do this:
apl$ tar xvf this fp tar: fp: Not found in archive tar: Error exit delayed from previous errors
apl$ tar xvf this ./fp ./fp/ ./fp/1 ./fp/t
If the archive listed as "//fp" etc, you'd need leading double slashes to restore (this is often seen from naive backup scripts): tar xvf this //fp
Although really nothing to do with tar per se, one mistake I commonly see is in the use of wild cards. For example, someone needs to restore /u completely. Their attempt will often be:
tar xvf /dev/tape /u/*
That "*" is very likely to screw them up, because it gets interpreted by the shell, and expanded to whatever is currently in /u. If there are missing directories, those won't be restored. If there is nothing in /u, the wild card pattern will be passed to tar, but not all tars understand what to do with wild cards, and absolutely none need them:
tar xvf /dev/tape /u
will always work.
Got something to add? Send me email.
More Articles by Tony Lawrence © 2011-07-06 Tony Lawrence