Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tar command

Status
Not open for further replies.

superstarjpmc

Programmer
Jan 22, 2004
38
US
i created a tar file using the below command.

tar cvf my.tar /tmp/*

This contains all the file/directories etc from /tmp directory.

My requirement is..

I want to un-tar the my.tar under a different directory... say /opt/mywork/

when I untar my.tar from /opt/mywork it untar's using the absolute path.. and doesnt create a directory /tmp under /opt/mywork..

can anyone help on this.

regs
 
In the tar man page search for an option (like -A) to remove leading / from the pathnames.
If your tar flavor doesn't offer this option, try to recreate your tar file like this:
[tt](cd /; tar cvf /path/to/my.tar ./tmp)[/tt]
If recreating the tarfile isn't an option and provided you're the only user logged in the system you may try something like this:
[tt]mv /tmp /tmp.bak
mkdir /opt/mywork/tmp
ln -s /opt/mywork/tmp /tmp
tar xf /path/to/my.tar
rm /tmp
mv /tmp.bak /tmp[/tt]
And next time avoid to archive absolute directory tree ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
pax can also untar absolute pathnames to different filesystems - have a look at the man page. HTH.
 
So you don't have pax nor gnu tar ?
Have you tried the symlink way I suggested ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Ignore that last link. Sorry. I would go with Ken or PHVs suggestions.
 
# tar tvf export_home.tar
tar: blocksize = 3
drwxr-x--- 201/1 0 Sep 5 10:16 2003 /export/home/gwhite/x/

# pax -r -s ',^/,,' -f export_home.tar

# ls
export export_home.tar

This worked and thanks.

While extracting the tar file ( i.e. after applying pax ).. i get an error as below.
Why is this ? eventhough my tar extraction is success.
>>>> tar: tape blocksize error

b) can someone explain what below command means.

>> pax -r -s ',^/,,' -f export_home.tar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top