Tag Archives: shell

Xargs – blank spaces in filenames

With xargs you can easily concat commands like:

find . -name *.metadata | xargs rm

But … if you have filenames with spaces (ie “my beautiful file.metadata”) the xargs command fails to perform the operation.
A possible solution is to use a null character:

$ find . -name *.metadata -print0 | xargs -0 rm

(find) “-print0” option: print theĀ  fullĀ  file name on the standard output, followed by a null character (instead of the newline character that -print uses)
(xargs) “-0” option: Input items are terminated by a null character instead of by whitespace