3

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?

5
  • Check out xargs --null or -0 argument. Commented Sep 23, 2012 at 8:25
  • I have but I don't see how it helps; I need to use printf with find. Commented Sep 23, 2012 at 8:29
  • 2
    @Emre: can you please post the full command you are trying to run? Commented Sep 23, 2012 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' Commented Sep 23, 2012 at 9:58
  • I was attempting to replace empty files that did not get copied properly by using find until I discovered rsync ... Commented Sep 24, 2012 at 5:27

2 Answers 2

5

Make sure you have -print0 in the find command.

find . -print0 | xargs -0 cmd ...
3

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.