Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between -L and -n in xargs

Tags:

xargs

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 
like image 801
camino Avatar asked Jan 12 '17 22:01

camino


People also ask

What is the difference between exec and xargs in Unix?

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.

What is the difference between pipe and xargs?

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").

What is xargs in shell script?

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.

What is xargs option?

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.


1 Answers

-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
like image 63
dosentmatter Avatar answered Nov 03 '22 01:11

dosentmatter