[CentOS] tar with pipe

Joshua Baker-LePain jlb17 at duke.edu
Sun Sep 25 16:55:32 UTC 2005

On Sun, 25 Sep 2005 at 6:52pm, Kai wrote

> Joshua Baker-LePain wrote:
>> *However*, that will keep the directory structure.  Why not just use cp?
>> find ../ -name '*.mp3' -o -name '*.ogg' -print0 | xargs -0 -i cp \{} .
> Thank you for explaining, cp would be find, but I don't understand your 
> arguments after the pipe.
> Please explain..
> I have tried to use find ....... -exec cp {}\; but cant get anything working 
> using the cp in this type of command.

xargs takes whatever comes in stdin and puts in after the commands which 
follow it.  If you give 'xargs' the '-i' flag, it instead takes what comes 
in on stdin and puts it whereever you put the '\{}' (note the location of 
the \).  'find | xargs' is *much* faster than 'find -exec' b/c you're not 
spawning a new process for every hit.  The '-print0' to find and '-0' to 
xargs use nulls to delimit each entry rather than whitespace -- this lets 
the command work on files/directory names with spaces in them.

Joshua Baker-LePain
Department of Biomedical Engineering
Duke University

More information about the CentOS mailing list