Fundamentals

Default behavior — xargs passes stdin as trailing arguments to echo
printf 'alpha\nbeta\ngamma\n' | xargs
One argument per invocation with -n1
printf 'alpha\nbeta\ngamma\n' | xargs -n1 echo "item:"
Two arguments per invocation with -n2
printf 'key1\nval1\nkey2\nval2\nkey3\nval3\n' | xargs -n2 echo
Line delimiter with -d to treat each line as one argument (GNU)
printf 'hello world\nfoo bar\nbaz qux\n' | xargs -d '\n' -n1 echo "line:"
One line per invocation with -L 1 (handles whitespace continuation)
printf 'hello world\nfoo bar\nbaz qux\n' | xargs -L 1 echo "line:"
Skip execution on empty input with --no-run-if-empty (-r)
# Without -r, xargs runs echo with no args (prints blank line)
echo -n "" | xargs echo "result:"
# With -r, xargs produces no output
echo -n "" | xargs -r echo "result:"
Prompt before each execution with -p
printf 'alpha\nbeta\ngamma\n' | xargs -n1 -p echo "process:"
Trace mode with -t — prints each command to stderr before execution
printf 'alpha\nbeta\ngamma\n' | xargs -n1 -t echo "item:"
Combine -t and -n1 to see exactly what xargs constructs
printf '/tmp\n/var\n/etc\n' | xargs -n1 -t ls -d
Batch size control — 3 args per invocation
seq 1 9 | xargs -n3 echo "batch:"