Operating System - HP-UX
1850111 Members
2459 Online
104050 Solutions
New Discussion

Re: TAR - simple extraction

 
SOLVED
Go to solution
rmueller58
Valued Contributor

TAR - simple extraction

My brain is full of mush today..

I am extracting a tar file,

I am using
"tar -xvf tarfilename"

it extracts files to the original location.

I want to extract files to a CWD.

Should the syntax be something like such?

"tar -xvf tarfilename newdir"
or
"tar -xvf tarfilename . "

For some reason the pathing in the tar file pushed files to a file system I have watch fairly closely for disk space, I'd prefer to extract to another location.

Any quick insight deeply appreciated.

12 REPLIES 12
Delcho Tuhchiev
Frequent Advisor

Re: TAR - simple extraction

Hi,

you can move the tar archive where you want to extract the files and then just to execute

tar -xf tarfilename

in this directory
melvyn burnard
Honored Contributor

Re: TAR - simple extraction

so how was the tarball created? using absolute paths?
do a tar tvf tarfilename to see.
If so, you will need to use pax to extract it to a new directory
My house is the bank's, my money the wife's, But my opinions belong to me, not HP!
john korterman
Honored Contributor

Re: TAR - simple extraction

Hi Rex,


there is a terrible hack:
First, cd to the direcotry, to which you want to extract.
However, the command below will restore the only the basename of the selected files:

$ pax -rv -s'/^\///' < tarfilename.tar

Perhaps other members have better - and not so quick - insights!


regards,
John K.
it would be nice if you always got a second chance
rmueller58
Valued Contributor

Re: TAR - simple extraction

mel,

the original tar command to create the archive is full path to our db export locations.

/mount/export/dbs/dbname/
melvyn burnard
Honored Contributor

Re: TAR - simple extraction

so, tar was done with full or absolute path naming.
You need to look at using pax to extract the files to another directory.
man pax

...
To read the archive a.pax, with all files rooted in the directory /usr
in the archive extracted relative to the current directory, enter:

pax -r -s ',//*usr//*,,' -f a.pax
My house is the bank's, my money the wife's, But my opinions belong to me, not HP!
Steven Schweda
Honored Contributor

Re: TAR - simple extraction

> the original tar command to create the
> archive is full path to our db export
> locations.
>
> /mount/export/dbs/dbname/

I trust that it's now clear why this was
probably unwise.

"pax" offers that "-s" option already
mentioned. GNU "tar" offers
"--strip-components=number" and
"--transform=sed-expr" (sounds like pax's
"-s"), either of which can help in this
situation.

http://www.gnu.org/software/tar/
rmueller58
Valued Contributor

Re: TAR - simple extraction

Mel

in your scenario:
pax -r -s ',//*usr//*,,' -f a.pax

If I modify this command to reflect

Say for example

pax -r -s ',//*exportfs//*,,' -f tarfile.tar

should take any files in the tarfile.tar and string off the leading exportfs? I have a deeply embedded directory structure..

/exportfs/dbexport/onconfig.pei/distname/dbname.exp/

How will that effect the result of the pax command ?



Sandman!
Honored Contributor

Re: TAR - simple extraction

>pax -r -s ',//*exportfs//*,,' -f tarfile.tar

>should take any files in the tarfile.tar and string off the leading exportfs? I have
> a deeply embedded directory structure..

>/exportfs/dbexport/onconfig.pei/distname/dbname.exp/

>How will that effect the result of the pax command ?

Are you trying to remove the leading "/exportfs" string and then extracting the tar archive to the current working directory with the rest of the path intact viz.,

# pax -v -r -f tarfile.tar -s?/exportfs/??g

strips off the leading "/exportfs/" string and extracts the remaining path name i.e. "dbexport/onconfig.pei/distname/dbname.exp/" in the CWD. Is that what you want?
rmueller58
Valued Contributor

Re: TAR - simple extraction

Sandman, yes, I want to extract the contents in current working and not put to the /exportfs/ mount point.

Bill Hassell
Honored Contributor

Re: TAR - simple extraction

Just to explain the problem, basic tar CANNOT restore to a different directory if the first character in the name of each file is: /

The / is the absolute pathname and tar has no options to restore that file to another location. Now there are tar enhancements such as gtar that do indeed have (non-standard) options to allow for this and if you must stay with tar, then downloading a copy of gtar is worth the effort. Be sure that you don't install gtar so it replaces /usr/bin/tar. You need to maintain each program separately.


Bill Hassell, sysadmin
melvyn burnard
Honored Contributor
Solution

Re: TAR - simple extraction

I would advise using pax, as it gives much more flexibility, and in fact as of HP-UX 11.31 HP recommend this command due to the portability, and also (off topic) fbackup/frecover are being obsoleted
My house is the bank's, my money the wife's, But my opinions belong to me, not HP!
rmueller58
Valued Contributor

Re: TAR - simple extraction

Thanks All, I will look into Pax a bit closer and GTAR..

Thanks All.