Topic: tech linux

tech linux > xargs

xargs

These are the options most commonly used with xargs, with examples.

Execute a command many times, with one argument per execution;

find <DIR> -type f | xargs -n 1 basename

xargs treats single quotes as a special character. The above command will fail if any of the filenames contain single quotes. Use null terminated strings instead;

find <DIR> -type f -print0 | xargs -0 -n 1 basename

Substitute the arguments into the command line at some point other than the end of t he command.

find <DIR> -type f -print0 |
    xargs -0 --no-run-if-empty -I {} cp {} <DESTINATION>