Make xargs execute the command once for each line of input

How can I make xargs execute the command exactly once for each line of input given?
It’s default behavior is to chunk the lines and execute the command once, passing multiple lines to each instance.

From http://en.wikipedia.org/wiki/Xargs:

find /path -type f -print0 | xargs -0 rm

In this example, find feeds the input of xargs with a long list of file names. xargs then splits this list into sublists and calls rm once for every sublist. This is more efficient than this functionally equivalent version:

find /path -type f -exec rm ‘{}’ \;

I know that find has the “exec” flag. I am just quoting an illustrative example from another resource.

13 Answers
13

Leave a Comment