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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Two questions about tar command

Status
Not open for further replies.

fabien

Technical User
Sep 25, 2001
299
AU
Hi!

1) I would like to extract the files from file.tar and change the path of the files. For instance, if in the tar file I have
/def/rr/toto/data/file1.dat
/def/rr/toto/data/file2.dat
/def/rr/toto/data/file3.dat

I want to get
/d/vc/tutu/data/file1.dat
/d/vc/tutu/data/file2.dat
/d/vc/tutu/data/file3.dat

Is this possible?

2)I would like to know how many files there are in an archive is tar -tvf file.tar | wc the best way to go?

Thanks!
 
1) man ln (the -s option)
2) tar -tf file.tar | wc -l

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
1Q: this files are absolutely tared, so...
man chroot
1Q: a good way

don't forget, RTFMP :) guggach
 
Also look at pax. I understand that this has an option to ignore the leading / in absolute pathnames, but have never used it myself.
 
PHV and guggach, thanks but I cannot be root.

Ken, your solution with pax is very interesting, how can I do a substitution from say /data/toto/titi to /t/rr/ll ?
 
In the man tar page you may discover an option to suppress absolute pathname.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
fabien:
root ONLY can read this file, because it's
absolute, ask for assistence by sys-admin, or
install an other sys, transfert the file,
become root perms...
please, for the future
NEVER do a tar/dump of absolute paths
you ALWAYS get problems
so: tar cfv /filename /xxx IS WRONG
but: tar cfv /filename ./xxx IS OK
the f... dot before slash is your livesaver.

don't forget, RTFMP :) guggach
 
Fabien, man pax, but also have a look at Thread52-567639 which gives an example. Good luck.
 
I agree with Ken.
man pax (the -s option)
The gnu tar may also be an option as it remove the leading / by default.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top