[CentOS] OT -- BASH
Paul Heinlein
heinlein at madboa.com
Thu Jun 22 12:40:43 UTC 2006
On Thu, 22 Jun 2006, James Pearson wrote:
> Robert wrote:
>> Can someone explain why this:
>> find . -depth -print0 | cpio --null -pmd /tmp/test
>> will copy all files in and below the current directory -and- this:
>> find . -depth -print | grep -v .iso$ | wc -l
>> will count all the non-iso files -and- this:
>> find . -depth -print | grep .iso$ | wc -l
>> will count *only* the iso files -but- this:
>> find . -depth -print0 | grep -v .iso$ | cpio --null -pmd /tmp/test
>> doesn't copy *anything*? Any suggestions for a work-around would also be
>> most welcome.
>
> Because -print0 generates a NULL separated list - so grep will match .iso\0
> in the string generated by find and hence not output any list for cpio to
> read ...
>
> One workaround:
>
> find . -depth -print | grep -v .iso$ | cpio -pmd /tmp/test
The -print0 command is typically used when find is passing filenames
with spaces or other characters that require a shell escape.
If the filenames are all shell-safe, then -print0 is unnecessary. If
there's a chance that even one name contains a space, however, then
-print0 is your friend.
-- Paul Heinlein <heinlein at madboa.com>
More information about the CentOS
mailing list