Skip to content
Latchkey

xargs -n: Limit Arguments Per Command

xargs -n N runs the command with at most N items at a time, splitting the input into batches.

Some commands accept only one argument, or you want fixed-size batches. -n controls exactly how many items each invocation receives.

What it does

xargs -n <max-args> uses at most max-args items per command line. With -n 1 the command runs once per item; with -n 10 it batches ten at a time. The final batch may have fewer items if the input does not divide evenly.

Common usage

Terminal
echo 1 2 3 4 5 | xargs -n 2 echo   # echo 1 2 / echo 3 4 / echo 5
cat urls.txt | xargs -n 1 curl -fsS
find . -name '*.bin' | xargs -n 100 sha256sum

Options

FlagWhat it does
-n <max>At most max items per command invocation
-n 1Exactly one item per run (one command per item)
-L <n>Like -n but counts input lines, not whitespace items
-s <size>Cap each command line at this many bytes

In CI

Use -n to chunk a large list into commands that each fit comfortably under the OS argument limit, or to satisfy tools that accept one path at a time. Remember -n counts whitespace-separated items, while -L counts lines; pick the one that matches your input.

Common errors in CI

A surprising last batch (fewer items than expected) is normal, not a bug. If a tool rejects multiple arguments you may need -n 1 and will see its own "too many arguments" error otherwise. Combining -n with -I is contradictory: -I already forces one item per run, so -n is ignored after -I.

Related guides

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