1825756 Members
2326 Online
109687 Solutions
New Discussion

assistance with tar

 
SOLVED
Go to solution
Ragni Singh
Super Advisor

assistance with tar

Hello,

I have a file that I would like to tar using relative path onto a tape. How would I do that. Any help will be greatly appreciated.
6 REPLIES 6
Sanjay_6
Honored Contributor
Solution

Re: assistance with tar

Hi Sanman,

Try this,

The file you want to tar is

/dir1/dir2/dir3/file_name

you are presently in /home/mydir

to take a tar backup, try

tar cvf /dev/rmt/device_file ../../dir1/dir2/dir3/file_name

Hope this helps.

Regds
Craig Rants
Honored Contributor

Re: assistance with tar

Let's say you are in / and you want to do this with /opt

tar cvf filename.tar ./opt

Then when you are done enter

tar tvf filename.tar

and verify that the files have a leading ., this will let you know for sure that they will extract relative to your current dir.

Good Luck,
C
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
Bernie Vande Griend
Respected Contributor

Re: assistance with tar

Couple different ways:

cd to / and put a . in front of the full path like: ./etc/fstab
tar cvf /dev/rmt/0m ./etc/fstab

or cd to the directory and tar up the file from there
cd /etc
tar cvf /dev/rmt/0m fstab

or tar the files up with the full path and use the pax utility to change the path when you untar them. pax is cool.
Ye who thinks he has a lot to say, probably shouldn't.
Mary Ann Lipa
Valued Contributor

Re: assistance with tar

The simplest way I can see is to cd one level higher to your target directory and do tar from there:



ex: you want to tar files under

/test/test1/test2

cd to /test/test1 then

execute:

#tar cvf test2





d_b
Which is worse, smoking or picking your nose in a public place?
Mary Ann Lipa
Valued Contributor

Re: assistance with tar

ooops, forgot the device file...

it should be

#tar cvf /dev/rmt/0m test2
Which is worse, smoking or picking your nose in a public place?
Darrell Allen
Honored Contributor

Re: assistance with tar

Hi Sanman,

Just remember that a relative path starts from your current directory. The relative path you specify when creating the tar file is how it will be extracted - BUT it will be relative to your current directory when you actually do the extract.

Example:
cd /home/sanman
tar cvf /dev/rmt/0m subdir1/subdir2/file1

By the way, you can choose to start the path with a "./" if you wish but that isn't neccessary.

So in the above example you have created a tarfile that contains one file. When you extract that file using tar it will be written to the same relative path but it will be relative to your current directory then.

So...
cd /var/tmp
tar xvf /dev/rmt/0m
will extract the file to /var/tmp/subdir1/subdir2/file1

If /var/tmp/subdir1/subdir2 does not exist, it will be created.

You could tar and extract the same file like this:

cd /home/sanman/subdir1/subdir2
tar cvf /dev/rmt/0m file1
cd /var/tmp
tar xvf /dev/rmt/0m

The difference with the second example is that the file will be extracted to /var/tmp/file1

Lastly, if you don't know if a tarfile was created using relative or absloute pathnames, use the "tv" options to see the contents of the tarfile.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)