Xargs -L1 vs -n 1 – Are They the Same?

xargs

From Search for and remove files safely

locate  -i nohup.out | xargs -d '\n' -L1 -p rm

Each line in the output of locate is treated as a argument by xargs, so are -L1 and -n 1 the same?

Thanks.

Best Answer

From the manual:

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

-n max-args
Use at most max-args arguments per command line. Fewer than max-args arguments will be used if the size (see the -s option) is exceeded, unless the -x option is given, in which case xargs will exit.

-d delim
Input items are terminated by the specified character. [...]

Based on this and my understanding, in your case -L1 and -n1 are made equivalent both by the argument 1 passed and the delimiter changed from blank space to \n (newline) by the argument -d

For example, without the -d argument if you were to have a blank space in your locate output, then this line would be splitted into two arguments and hence 2 different use of rm with -n1, while it would still be treated as one argument and only one command with -L1

Related Question