[Linux-disciples] xargs -0

Adam Rosi-Kessel adam at rosi-kessel.org
Tue Jul 11 17:38:27 EDT 2006


Stephen R Laniel wrote:
> On Tue, Jul 11, 2006 at 02:54:42PM -0400, Adam Rosi-Kessel wrote:
>> grep -Zirl [pattern] [sourcePath] |
>>                      tr "\n" "\0" |
>>       xargs -0i cp "{}" [destPath]
> 
> The trouble with that is: what if the file contains
> apostrophes or quotes? Then the '{}' thing will break. E.g.,
> 
> (16:03) slaniel at inwalkedbud:~/testdir$ grep -Zirl stuff .  |tr '\0' '\n' |xargs -0i cp '{}' ..
> cp: cannot stat `./file\'s name contains "" (quotes)\n./file\'s name contains apostrophe\n': No such file or directory

Sorry, you need to do xargs -i -0. That should work.

Is that an actual copy from your commandline? If so, you've got the \0 and
\n transposed.

> whereas
> grep -Zirl stuff . |xargs -0 mv --target-directory=/home/slaniel
> works fine.



More information about the Linux-disciples mailing list