Skip to content
Latchkey

xargs -L: One Command Per N Input Lines

xargs -L N runs the command once for each group of N nonblank input lines.

When your input is line-oriented, like a list where each line is one record, -L groups by lines instead of by whitespace-separated words the way -n does.

What it does

xargs -L <max-lines> uses at most max-lines lines of input per command invocation. Unlike -n, which counts whitespace-separated items, -L counts lines, so a line with several words still feeds all those words into one run. A trailing blank line ends a logical line group.

Common usage

Terminal
# one curl per line, each line is a full URL with query string
xargs -L 1 curl -fsS < urls.txt
# process pairs of lines together
printf 'a\nb\nc\nd\n' | xargs -L 2 echo

Options

FlagWhat it does
-L <max>Run the command per max input lines
-L 1One command per line (words on the line stay together)
-n <max>Counts whitespace items, not lines
(trailing space)A line ending in whitespace continues to the next line

In CI

Reach for -L when each line is a complete record that may contain spaces you want kept together, and for -n when you want a fixed number of discrete arguments per run. They are easy to confuse; -t helps you confirm which grouping you actually got.

Common errors in CI

A line that ends in a space is treated as continuing into the next line under -L, which can merge records unexpectedly; trim trailing whitespace first. Mixing -L and -n is implementation-defined and the later flag tends to win, so set only one.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →