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.
More Articles by Tony Lawrence - Find me on Google+
Have you tried Searching this site?
Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates
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. We appreciate comments and article submissions.
Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.
Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.
We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.
Click here to add your comments
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.
Also, take a look at the ptar function.
--BigDumbDinosaur
Don't miss responses! Subscribe to Comments by RSS or by Email
Click here to add your comments
If you want a picture to show with your comment, go get a Gravatar