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!

help with xargs

Status
Not open for further replies.

Wrathchild

Technical User
Aug 24, 2001
303
US
tar tf test.tar | xargs -i cp -r -f {} backup

I am trying to copy files that match those in the test.tar file into the backup directory. There are subdirs with files also and these are designated properly within the tar file. The files all get copied to the proper locations in backup, HOWEVER they are all getting copied to the top-level backup dir in addition to their proper locations. Also the subdirs themselves are being replicated at the top-level backup dir. I'm close, can anyone see what's wrong with my command?
thanks!
 
What about this ?
tar cf - `tar tf test.tar` | (cd backup; tar xf -)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
thanks PHV, once again you've outdone yourself; if you wouldn't mind could you explain the syntax so I understand what's going on? Especially the left side of the pipe - what's tar cf - doing? Is this creating a temp tar file then untarring it?
 
The - in PHV's script is stdout/stdin so the script
[ol]
[li]takes a list of all the files in test.tar using tar -tf[/li]
[li]creates a tar file (tar -c) using stdout as the 'file' (-f -)[/li]
[li]That stdout is piped to the next process which is[/li]

[li]cd to the backup dir[/li]
[li]untar the input from stdin (tar -xf -)[/li]
[/ol]

Another way to do this is to use cpio in passthrough mode.
Try
Code:
tar -tf test.tar | cpio -pdl /path/to/backup
The AIX man page gives an example of this.

On the internet no one knows you're a dog

Columb Healy
 
Err... update... the -l flag on cpio links, not copies which is probably not what you want. It should have been
Code:
tar -tf test.tar | cpio -pd /path/to/backup

On the internet no one knows you're a dog

Columb Healy
 
cool, so it's basically a temp tar process..thanks guys
 
I received "end-of-file" error messages when testing out PVH's method with real-world data; too many files. I'm attempting to use cpio per columb's solution, but receiving the following errors. I'm brand new to cpio and have browsed the documentation. Not sure if cpio is supposed to be writing to a file specifically?

$ vi test.sh
change=555555
mkdir /tmp/$change
tar tf test.tar | cpio -pd > /tmp/$change


$ test.sh
Cannot write to a directory.
test.sh[4]: /tmp/555555: 0403-005 Cannot create the specified file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top