Make xargs execute the command once for each line of input

Posted by Readonly on Stack Overflow See other posts from Stack Overflow or by Readonly
Published on 2008-10-13T22:31:24Z Indexed on 2010/04/15 14:43 UTC
Read the original article Hit count: 300

Filed under:

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.

© Stack Overflow or respective owner

Related posts about xargs