1831078 Members
2537 Online
110019 Solutions
New Discussion

Re: tar question

 
SOLVED
Go to solution
Sanjay Tailor
Frequent Advisor

tar question

Hello,
I have a tar file and would like to restore it. i use the command tar -xv. But this tries to restore it to the original location. Can I tell tar to restore the files to another location (directory) on the system?

Thank you for your help.


12 REPLIES 12
Rick Garland
Honored Contributor

Re: tar question

tar -xvC I believe is the option you are looking for.

man tar to find the options you would need
Sanjay Tailor
Frequent Advisor

Re: tar question

Hello,
That option did not work. I tried that and looked at the man page and there is no reference to restoring to a specified directory or none that I could find.

Thanks,
CHRIS_ANORUO
Honored Contributor

Re: tar question

Use tar -exvf, tar restores from you stand point when issueing the extract command.
When We Seek To Discover The Best In Others, We Somehow Bring Out The Best In Ourselves.
Fred Martin_1
Valued Contributor

Re: tar question

If you get a listing of the files, does it show them with absolute pathnames, starting with a slash? If so, tar will always attempt to restore to original locations. If the pathnames are relative, ie starting with a dot or filename, the restore begins at the current directory.
fmartin@applicatorssales.com
Richard Lathom
Occasional Advisor

Re: tar question

Can't be done. Tar will do two(2) things depending on the way the tarball was created.
Do a "tar -tvf" and capture the output. If the filenames begin ./ , then the restore will be relative to the directory you are in when doing the "un-tar". If the filenames begin with / , then the restore will always be relative to /(root). You can't change this behaviour. Tar is an old utility but useful because all unix OSes have it.

Richard Lathom
Sanjay Tailor
Frequent Advisor

Re: tar question

Hello,

Just as I had surmised. So, when I create the tar how do I create it to use relative file names? My tar right now has absolute paths in it.

Thanks,
Andy Monks
Honored Contributor

Re: tar question

Hi Sanjay,

Firstly, you can recover your existing tar backups. You can use 'pax'. It can recover absolute tar backups, relatively.

To do you tar back relative do :-

tar cvf /dev/rmt/0m ./etc ./usr

or

tar cvf /dev/rmt/0m .

which will backup everything from where your current directory is.

The important thing is to being everything with './'

Andy
Alan Riggs
Honored Contributor
Solution

Re: tar question

If the tar file was created with relative pathing (always recommended) then simply go to the directory under which you want teh files restored and use tar xvf.

ex:
cd /where/I/want/it
tar vxf /wpath/to/tar/file

If the tar was created using absolute paths, I do not believe there is a way to override it in the tar command.
Carlos Fernandez Riera
Honored Contributor

Re: tar question


Pax command allows conversion of absolute paths to relative paths using -s option. Pax can read tar files.

This is the only way i know in HP-UX...

but in a SCO you can do tar xvfA. 'A' option converts form absolute to relative paths.

Well, when i must do this in HP-UX i use symbolic links:

if i must restore files under /dir/data:

mv /dir/data /dir/data.o
mkdir /tmp/data
ln -s /tmp/data /dir/data
tar xvf ....
rm /dir/data
mv /dir/data.o /dir/data

So i can extract to /tmp.


HTH

unsupported
Andreas Voss
Honored Contributor

Re: tar question

Hi all,

i think the best solution is to use pax:

pax -rv -s'/^BACKSLASH///'
This will restore the archive into the current directory (look out for pwd).

I have noticed that the Backslash is not submitted by the reply so i have written it symbolic (BACKSLASH). Of course you must use the Backslash key by entering the command.

Greetings

Andrew
Fred Martin_1
Valued Contributor

Re: tar question

Did you get the answer to your question about creating tar files with relative pathnames?

You just 'cd' to the directory where you want the tar to begin. For example, if you have the following:

/usr/local/bin/etc....

If you want to tar everything in bin, including the bin directory:

cd /usr/local
tar cvf tarfile

The files in the tarfile will look like this:

bin/script1
bin/script2
bin/data

...etc

Then you can restore it anywhere you like:

cd /home/fred
tar xvf tarfile

...will create a 'bin' directory under 'fred'


fmartin@applicatorssales.com
Fred Martin_1
Valued Contributor

Re: tar question

Did you get the answer to your question about creating tar files with relative pathnames?

You just 'cd' to the directory where you want the tar to begin. For example, if you have the following:

/usr/local/bin/etc....

If you want to tar everything in bin, including the bin directory:

cd /usr/local
tar cvf tarfile

The files in the tarfile will look like this:

bin/script1
bin/script2
bin/data

...etc

Then you can restore it anywhere you like:

cd /home/fred
tar xvf tarfile

...will create a 'bin' directory under 'fred'


fmartin@applicatorssales.com