Everyone loves xargs. Except me. I hate it.
But, but, everyone loves
$ ls | grep foo | xargs rm
Weird, because:
$ rm $(ls | grep foo)
is a lot shorter. To understand why I hate it, look at the bugs section.
The -L option is incompatible with the -I option, but perhaps should not be.
Huh? Two options of the same program are incompatible. That sounds like bad design. And, well, that’s because it’s bad design.
And from xarg’s bad design, we can learn good design and therefore faster coding.
Let’s keep digging:
-L, from the man page
-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.
and for example:
$ seq 10 | xargs -L 3
1 2 3
4 5 6
7 8 9
10
I love xargs -L. It’s really great for grouping lines. No other program does it.
UPDATE 2020-07-18, taharqa and others showed me that paste can be used to do this:
$ seq 10 | paste -d' ' - - -
I now hate xargs -L.
-I, from the man…