1833784 Members
2234 Online
110063 Solutions
New Discussion

Re: tar

 
SOLVED
Go to solution
Shivkumar
Super Advisor

tar

Hi,

What is the command syntax for untarring tar file to specified path ?

What is mega tar ? Is it tar of many tar files ? Is there any advantage of it ?

Thanks,
Shiv

12 REPLIES 12
Patrick Wallek
Honored Contributor
Solution

Re: tar

How you created the tar file determines how you un-tar it.

If you used explicit paths, like 'tar -cvf file.tar /home/me' then it is difficult to restore to any place other than /home/me.

However if you used relative paths:

# cd /home
# tar -cvf file.tar ./me

Then it is easier to restore somewhere else.

# cd /newdir
# tar -xvf file.tar

This will restore ./me in the /newdir directory.

If you must restore a tar file created with explicit paths to a different directory you can make use of the 'pax' command. Do a 'man pax' for details. I can't recall the exact syntax you would need at the moment.

As for "mega tar" -- I have no idea what it means. I guess it would depend entirely on the context in which it is being used.
Rajeev  Shukla
Honored Contributor

Re: tar

The untar (tar -xvf) will untar in the directory where you run the command from if the tar was not run with a absolute path. meaning...
say you tar the files tar -cvf /tmp/tcb/tar /tcb
then no matter from where you untar them the files will always be untared in /tcb
But if you cd to the directory
cd / and then tar the directory then when you untar them it will create tar/files...in the directory from where you run the untar command

Never heard of mega tar
Gurumanickam
Frequent Advisor

Re: tar

hi shiv,

To create a tar you can use

tar -cvf destination(test.tar) source(/home)

to untar you can use

tar -xvf destination(path of new dir) source(test.tar)

Thanks
Be an expert
Yang Qin_1
Honored Contributor

Re: tar

Shiv, you can browse the content of tar file with: tar -tvf /aaa/bbb/xxx.tar
Vibhor Kumar Agarwal
Esteemed Contributor

Re: tar

4 basic tar commands:

c -> create
x -> extract
t -> type
u -> update
Vibhor Kumar Agarwal
Rashid Hamid
Regular Advisor

Re: tar

normally I used the easy way. go to that desire directory and untar it

cd /tmp
tar xvf file.tar

or

tar xvf file.tar .

I'm Parit Madirono/Parit Betak Boyz
Shivkumar
Super Advisor

Re: tar

I am just curious to know some more opinions of our respected Gurus on this issue.

Regards,
Shiv
Steven Schweda
Honored Contributor

Re: tar

It would help to know exactly what's in your
"tar" archive ("tar t"), and where you'd like
the files to end up. Knowing neither where
you're starting nor where you wish to go
makes it hard to say how you should try to
get there. Creating the archive with
absolute path names, for example, can make it
harder to control the path names of the files
when they're extracted.

The "tar" programs which come with most
commercial UNIX operating systems tend to be
rather limited. With HP-UX, an alternative,
"pax", offers a "-s" option which can be used
to transform file names when creating an
archive or extractling files from one.
("man pax".)

Similarly, GNU "tar" offers options like
--strip and --transform, which also can be
used to transform file names similarly.

http://www.gnu.org/software/tar/
http://www.gnu.org/software/tar/manual/index.html
http://www.gnu.org/software/tar/manual/html_node/transform.html
Steven E. Protter
Exalted Contributor

Re: tar

Shalom Shiv,

It's been a while since I answered one of your posts so HI!.

Generally, I am lazy so I put the tar file where I want it to untar and do tar xvf filename.tar

There are options built into tar for redirecting the output but I've found they don't always work as expected.

tar tvf lets me look at the tar archive without actually untarring it.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Shivkumar
Super Advisor

Re: tar

Which option allows me for untarring at different locations ? sorry to ask you because i just can't check it today being sunday here. Now i work for different company and i don't have remote access to the servers from home so that i can verify right now.

Secondly, does it work with GNU's tar ?

Best Regards,
Shiv
James R. Ferguson
Acclaimed Contributor

Re: tar

Hi Shiv:

> Which option allows me for untarring at different locations?

As Patrick noted, if you made your 'tar' archive with *relative* paths, then this is as simple as he showed in his example.

If you created your archive with absolute paths, you can use 'pax'. Consider the case where files in '/olddir' are to be extracted and placed into '/newdir'. The '/newdir' directory does need not exist, either:

# pax -r -p e -s '%^/olddir/%^/newdir/%' -f /dev/rmt/0m

...or:

# pax -r -p e -s '%^/%/newdir/%' -f /dev/rmt/0m

Notice that I've used the caret (^) to anchor the slach (/) to the beginning of the string specified -- that is to denote the absolute path's starting point.

As for being "at home" and not have a server available, you still have the HP documentation site, in this case the *manpages*:

http://www.docs.hp.com/en/hpuxman_pages.html

For GNU software, there is the invaluable resource here:

http://www.gnu.org/manual/manual.html

Regards!

...JRF...

Shivkumar
Super Advisor

Re: tar

Thanks James and others!!

Best Regards,
Shiv