Make your own free website on Tripod.com
Last updated Dec 18 2002
tar
Tape ARchiving



Create a compressed tar file.
    $ tar cvfz newarchive.tar.gz /mydirectory

Extract the contents of a compressed tar file.
   
$ tar xvfz existing.tar.gz



$ tar cf - . | ( cd /dest ; tar xfp -)

Run this from the source directory.  Move many files from one area to another saving permissions.
Meaning:
tar
cf  =  create file
-  =  stdout
.  =  of the current directory
|  =  pipe stdout of this command to stdin of the next command
(   )  =  do in new shell
cd /dest  =  change to the destination directory
;  =  next command
tar
xfp  =  extract filename preserve permissions
-  =  stdin


Used for backing up a system or transfering a lot of files as one file.  Many uses do not include using tape nowadays.

Tar does not compress the files.  It archives a number of files into one file.  Newer versions tar support compression, with the appropiate switch.


Without compression

Create a tar file.
    $ tar cvf newarchive.tar /mydirectory

This will create a file called newarchive.tar containing copies of all the files and directories in the directory /mydirectory.

cvf   c=create, v=verbose, f=file

You should not create a tar file in the directory that you are archiving.  The GNU version of tar will give you an error but work fine.  Other versions may go into a endless loop.


List the contents of a tar file without extracting the files.
    $ tar tvf existing.tar


Extract the contents of a tar file.
    $ tar xvf existing.tar

This will extract the contents of the tar file into the current working directory.
If you are extracting in to an existing directory, any files in the archive with the same name as an existing file will overwrite the existing file.


With compression

compress - older - filename.tar.Z
gzip - newer - filename.tar.gz  or  filename.tar.z

compress can't handle gzip files but gzip can handle compress.

The GNU version of tar supports gzip(un)compression.

Create a compressed tar file.
    $ tar cvfz newarchive.tar.gz /mydirectory

Extract the contents of a compressed tar file.
    $ tar xvfz existing.tar.gz




Index