Department of Statistics
University of Illinois at Urbana-Champaign
TAR - Tape ARchive
A tar file is a collection of files. In its most basic use, the tar command adds files to a tar file or extracts files from a tar file. The tar command is so useful because you can easily move tarfiles around. Altough the name tar (which comes from Tape Archive) refers to a tape, you don't need to use a tape. A tar file conventionally ends with a .tar suffix.
tar [flags] [the location or name of the tar file] [files to add or extract]
ux6> tar -cvf tarfile.tar readme.txt stat100 stat410 readme.txt stat100/ stat100/hw1.txt stat410/ stat410/hw1.txt
ux6> tar -uvf tarfile.tar newfile.txt newfile.txt
ux6> tar -xvf regress.tar regress/ regress/readme.txt regress/somefile.c regress/anotherfile regress/updates
ux6> cd ux6> ls chem210 mbox reminder stat100 stat452 test ux6> tar -cvf mytarfile.tar stat100note the flags
stat100/ stat100/dataset stat100/old/ stat100/old/hw1.txt stat100/old/notes.txt stat100/hw1.txt stat100/hw2.txt stat100/hw3.txt ux6> ftp ux1 [login] ftp> bin ftp> put mytarfile.tar ftp> quit ux6> telnet ux1 [login] ux1> ls mbox mytarfile.tar ux1> tar -xvf mytarfile.tar stat100/ stat100/dataset stat100/old/ stat100/old/hw1.txt stat100/old/notes.txt stat100/hw1.txt stat100/hw2.txt stat100/hw3.txt ux1> ls mbox stat100 mytarfile.tar
ls -ap
to get a listing of all the files in a directory.
a
flag will force listing off all files,
including files with a . prefix.
p
will add a /
after the name of a directory.
>
redirector to send the output of the ls
into a new file.
./
and ../
), otherwise you'll
run into a mess. Be aware that if you include the name of a directory,
tar will include all the files within that directory.
tar -cvf
,
use the cat
command within a set of backticks (`
)
as follows:`cat filename`
.
ux6> c ux6> ls -a > filelist ux6> [edit filelist as above] ux6> tar -cvf newtarfile.tar `cat filelist`
One way to avoid this problem: Create a temporary directory
which you extract the tar file into. Then you can use cp
or mv
to re-organize your files.
ux6> cd ux6> tar -cvf newtarfile.tar .All the files in your home directory will be added to the file newtarfile.tar. This is a good start, but now the file newtarfile.tar is also in your home directory, so the tar process will try to add the file newtarfile.tar to itself. Newer versions of tar will prevent you from doing this.
Be sure that the location of your new tarfile is not in the path of the files you are adding to the new tarfile. /tmp is one possibile location, but may not be too secure.
ux6> cd ux6> cd furniture ux6> tar -cvf /tmp/furniture.tar . ./ desk chair table
ux6> cd ux6> cd furniture ux6> cd .. ux6> tar -cvf furniture.tar furniture furniture/ furniture/desk furniture/chair furniture/table
man
pages to get even more use out of the tar
command: man tar
Back to Department of Statistics home page
Last Updated 4/2/97