Tuesday, June 4, 2013

Unix: Using 'find' and 'xargs' on filenames that have spaces within them

To use find and xargs effectively together, use -print0 to separate filenames with a null character instead of new lines. Along with that, use -0 with xargs.

$ touch "my file"
$ find | xargs ls
ls: ./my: No such file or directory
ls: file: No such file or directory
$ find -print0 | xargs -0 ls
./my file 

No comments:

Post a Comment