einpoklum
einpoklum

Reputation: 131533

Easiest way to escape the output of find?

I want to do something like

find . -name "*whatever*" | xargs zip my.zip

but if the files I'm finding contain certain characters, this gets messed up, for example with spaces within the filenames. I guess I should escape the results. I couldn't quite understand from man find whether it could do this for me. So:

Upvotes: 2

Views: 973

Answers (1)

James K
James K

Reputation: 617

Null separation was made for this exact case.

find can be instructed to separate its outputs with NUL characters (0's) via the -print0 option.

xargs can be instructed that its incoming arguments will be NUL separated with the -0 option.

Hence,

find . -name "*whatever*" -print0 | xargs -0 zip my.zip

Upvotes: 3

Related Questions