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 multip
If you want to run the command for every line (i.e. result) coming from find
, then what do you need the xargs
for?
Try:
find
path -type f -exec
your-command {} \;
where the literal {}
gets substituted by the filename and the literal \;
is needed for find
to know that the custom command ends there.
(after the edit of your question clarifying that you know about -exec
)
From man xargs
:
-L max-lines
Use at most max-lines nonblank input lines per command line. Trailing blanks cause an input line to be logically continued on the next input line. Implies -x.
Note that filenames ending in blanks would cause you trouble if you use xargs
:
$ mkdir /tmp/bax; cd /tmp/bax
$ touch a\ b c\ c
$ find . -type f -print | xargs -L1 wc -l
0 ./c
0 ./c
0 total
0 ./b
wc: ./a: No such file or directory
So if you don't care about the -exec
option, you better use -print0
and -0
:
$ find . -type f -print0 | xargs -0L1 wc -l
0 ./c
0 ./c
0 ./b
0 ./a