Monday, February 8, 2010

How to use TAR

Tar is a good utility to produce a backup. When you create a tar archive the destination locatiion could be a tape or a regular file. Note that tar can preserve file's permission and its mode.

For example, you have the following directory structure:

/home/oracle/alex/test
/home/oracle/alex/test/ems
/home/oracle/alex/test/vtools8
/home/oracle/alex/test/psaor01


Create an archive

To create an archive of the entire test directory, issue the following command:

tar cvf my_arch.tar /home/oracle/alex/test

If you want to include into your archive several different directories you might use the following command:

tar cvf my_arch.tar -I include.lst

where the -I option specifies the name of a file with a list of directories and files that you want to include into your archive.

Also, it's possible to exclude certain files and directories from your archive:

tar cvfX my_arch.tar exclude.lst -I include.lst


List an archive contents

To list the contents of your archive issue the following command:

tar tf my_arch.tar


Extract from an archive

To extract the contents of your archive:

tar xvfp my_arch.tar

Note, that everything will be extracted exactly at the same location from where it was taken. If some directories do no exist then they will be created.


Legend of tar's options

c - add to archive, using an absolute path
x - extract from archive
t - read the contents of an archive
f - you work with a file, otherwise it's a tape
p - preserve file's permissions and modes
v - verbose, display the result
-I - use an include list
X - use an exclude list

No comments:

Post a Comment