Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a list of files generated using find that I want to feed (pipe) to cp. My problem is that the files have spaces and apostrophes in them, leading cp to repeatedly complain that it "cannot stat". Is there an elegant solution to this problem?

share|improve this question
    
Check out xargs --null or -0 argument. –  jasonwryan Sep 23 '12 at 8:25
    
I have but I don't see how it helps; I need to use printf with find. –  Emre Sep 23 '12 at 8:29
2  
@Emre: can you please post the full command you are trying to run? –  Francesco Turco Sep 23 '12 at 9:20
3  
Why do you need to use printf? Do you mean the printf command or the -printf option to find? Note that find ... -print0 is equivalent to find ... -printf '%p\0' –  Keith Thompson Sep 23 '12 at 9:58
    
I was attempting to replace empty files that did not get copied properly by using find until I discovered rsync ... –  Emre Sep 24 '12 at 5:27
add comment

2 Answers 2

up vote 5 down vote accepted

Make sure you have -print0 in the find command.

find . -print0 | xargs -0 cmd ...
share|improve this answer
add comment

Another option is to skip -print0 and the pipe, and instead use the -exec cp {} path/to/dest/ + or -exec cp {} path/to/dest \; commands to find. The first replaces {} with a whole bunch of found filenames at once; the second copies found files one-at-a-time. These commands are present on most find implementations.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.