Skip to content
Latchkey

xargs -a: Read Items From a File

xargs -a <file> reads the item list from a file rather than standard input.

When you have a manifest of paths or hosts on disk, -a feeds it to xargs directly, leaving stdin available for the spawned command.

What it does

xargs -a <file> (GNU) reads items from the named file instead of standard input. This matters when the command you run also wants stdin, since reading items from a file keeps the two streams separate. It combines with -0, -n, -P, and -I as usual.

Common usage

Terminal
xargs -a packages.txt -n 1 npm install
xargs -a files.nul -0 rm                 # NUL-delimited file
# portable equivalent without -a
xargs -n 1 npm install < packages.txt

Options

FlagWhat it does
-a <file>GNU: read items from file instead of stdin
(with -0)Read a NUL-delimited file safely
(keeps stdin free)Command can still read its own stdin
< file (portable)Redirect the file into stdin where -a is missing

In CI

Use -a when the per-item command needs stdin, for example a tool reading config from a pipe. On macOS runners -a is not available, so use the portable "xargs ... < file" redirect, which has the same effect for the common case.

Common errors in CI

On BSD/macOS xargs, -a fails with "xargs: illegal option -- a"; switch to the "< file" redirect. "xargs: cannot open: No such file or directory" means the file path passed to -a is wrong. If the file is NUL-delimited, remember to add -0 or items will be misparsed.

Related guides

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