Per xargs --help:
-L, --max-lines=MAX-LINES use at most MAX-LINES non-blank input lines per command line
-n, --max-args=MAX-ARGS use at most MAX-ARGS arguments per command line
It is very confusing. Is there any difference between -L and -n?
ls *.h | xargs -L 1 echo
ls *.h | xargs -n 1 echo
since this asks about the differences and that question asks about which is faster, but the difference is that xargs invokes the command in batches while find -exec invokes the command once per result, which makes xargs faster.
Originally Answered: What is the difference between | and xargs? | named pipeline. It pipe previous program's stdout to next program's stdin. xargs read from stdin every line, and execute command which specified from args(when "xargs -n 1").
xargs (short for "eXtended ARGumentS") is a command on Unix and most Unix-like operating systems used to build and execute commands from standard input. It converts input from standard input into arguments to a command.
xargs reads items from the standard input, delimited by blanks (which can be protected with double or single quotes or a backslash) or newlines, and executes the command (default is echo) one or more times with any initial-arguments followed by items read from standard input.
-n
splits on any whitespace, -L
splits on newlines.
Examples:
$ echo {1..10}
1 2 3 4 5 6 7 8 9 10
$ echo {1..10} | xargs -n 1
1
2
3
4
5
6
7
8
9
10
$ echo {1..10} | xargs -L 1
1 2 3 4 5 6 7 8 9 10
$ seq 10
1
2
3
4
5
6
7
8
9
10
$ seq 10 | xargs -n 1
1
2
3
4
5
6
7
8
9
10
$ seq 10 | xargs -L 1
1
2
3
4
5
6
7
8
9
10
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With