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
I must:
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
640K ought to be enough for anybody. (Bill Gates)
It should be noted that the version of tar shipped with SCO OSR5 has a path name length limit of 99 characters. This limitation can cause failures when backing up nested directories into which Windows-generated files are stored. Oftentimes, Windows users will create ridiculously long filenames (espcially with MS Word) that practically reiterate the file contents. <Smile>
Also, take a look at the ptar function.
--BigDumbDinosaur
------------------------
Printer Friendly Version
tar Copyright © November 2003 Tony Lawrence
Have you tried Searching this site?
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.
Contact us
Printer Friendly Version