D   A   T   A   W   O   K

Creation: January 01 1970
Modified: September 11 2018

Find and XArgs


By default find use the newline as output separator. To replace the newline with a null character use the print0 option after the last find argument.

Find process arguments in a positional manner. This means that find . -name "*.asd" -print0 gives a different output from find . -print0 -name "*.asd". Probably what you want, in this case, is the first one.


Testing options

Remove all tmp/*.mp3 messages only in the specified directory (ignore sub directories)

$ find tmp -maxdepth 1 -name '*.mp3' | xargs rm

Arguments can be manually batched using the -n option.

$ find tmp -maxdepth 1 -name '*.mp3' | xargs -p -n1 rm

The above command removes one file at a time asking for confirmation.

Filanames with spaces can cause problems.

Argument list marker

{} is the default argument list marker. You need to use {} with commands taking more than two arguments at a time.

For example, the mv command

$ find . -name "*.bak" -print0 | xargs -O -I {} mv {} ~/old.files