1753481 Members
4600 Online
108794 Solutions
New Discussion юеВ

create a tar file

 
Gemini_2
Regular Advisor

create a tar file

Hi, my tar files are under ~/test. when I create the tar ball, I want it to prefix with /tmp. how do I do that?

for example
my step now is
cd ~/
tar -cvf test.tar test/*

tar -tvf show
~/test/1
~/test/2

how can I change it to
/tmp/test/1
/tmp/test/2

I know that I can move files to /tmp, and then create the patch there...but is there a better way?

thank you


10 REPLIES 10
Torsten.
Acclaimed Contributor

Re: create a tar file

simply specify the output path to the tar command:

tar -cvf /tmp/test.tar test/*

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
generic_1
Respected Contributor

Re: create a tar file

remove test/ from your syntax cd into that directory and do tar -cvf /yourfile.tar *. Then cd to the restore directory say /tmp/test1 and restore there.
Rodney Hills
Honored Contributor

Re: create a tar file

Usually you don't want absolute path names in a tar file.

cd ~/
tar cf test.tar test/*

is what you want to do.

To restore to tmp, you would then

cd /tmp
tar xf ~/test.tar

gnu tar might be able to do what you want.

HTH

-- Rod Hills
There be dragons...
James R. Ferguson
Acclaimed Contributor

Re: create a tar file

Hi:

Generally speaking making 'tar' archives with relative paths provides the most flexability.

That said, however, I'd look at 'pax' ('tar's cousin). 'pax' gives you the opportunity to do regular expresssion substitutions o the archive member names.

See the man pages for 'pax' and the '-s' option therein.

Regards!

...JRF...
Gemini_2
Regular Advisor

Re: create a tar file

the tar file is created and used by others.

in case if people forget to cd to /tmp, I still want tar to handle it, that is why.

look the only solution is
cp ~/tests/* /tmp/tests.
tar -cv test.tar /tmp/tests/*

hmm.....




Gemini_2
Regular Advisor

Re: create a tar file

pax is not standard linux redhat rpm package right?
Tim D Fulford
Honored Contributor

Re: create a tar file

Hi

DONT make absolute tar files, you get get in a whole heap of problems doing this...

try

# cd /tmp; tar xf test.tar

Tim
-
Rodney Hills
Honored Contributor

Re: create a tar file

"pax" is an hpux utility.

That is what this forum is about....

Rod Hills
There be dragons...
James R. Ferguson
Acclaimed Contributor

Re: create a tar file

Hi (again):

'pax' exists on AIX too! It's not just HP-UX.

Regards!

p.s. Thanks, Rodney :-)

...JRF...