Neill Jones wrote:
n Tuesday 23 May 2006 09:17 am, Duncan Anderson wrote:
  
 No problem. I like the mosquito/sledgehammer analogy. Tell me, do you know
how to overcome the problem of file names being rejected by find when they
contain spaces, etc.?
    

No never had any of those probs, I think. What exactly do you mean?
All files including the ones with spaces show up.

I mostly use find in combination with cpio to copy/move contents from one 
(usually almost full) partition to another. Never lost a file.

Just yesterday I copied a 7G partition's content (my old 32_bit / partition I 
still keep in reserve) from a dying HD to a new one. Compared 'em and didn't 
loose a single thing. Still boots up fine after editing its "/etc/fstab".

the whole (lovely unixy) command is "find . | cpio -padm /mnt/new_partition" 
whilst being in the topmopst directory of the to be copied partition, BTW.
  
I'll second that - just tried find on a set of files with spaces in their names and it finds
them with no problems. If you want to pipe these through to other programs, you can
use the -print0 (that's print and a zero) option which ends each file with a null rather
than a newline (see man find). Then you can use xargs -0 to read them in. So you could
do something like
find . -iname "*.*" -print0 | xargs -0 grep -i "searchitem"
  
to find searchitem within a set of files with spaces. (The -i's mean case insensitive)
Just for info and clarity:

A minor extra to H.J.Bathoorns post ... in the above, it is not the -iname which causes
problems with the spaces, it is the use of xargs. For example,
find . | grep "filename" 
works as pointed out by Harm. Also
find . -iname "*.txt" | grep "filename"
will work with all .txt files found. In both cases this can be understood since find returns
each find item with a new line after it. grep then just reads each line of standard in which
is a full line with the file name on it. When these are combined together as parameters for
xarg however the spaces are seen as parameter breaks and so cause problems. Then you need
to use the -print0 and xargs -0 options.

Regards

Neill


Reply via email to