Skip to content
Latchkey

xargs -d: Set a Custom Input Delimiter

xargs -d sets the input item separator to a character you choose instead of whitespace.

When items are separated by newlines only (so spaces inside an item are fine) or by some other character, -d lets you split on exactly that.

What it does

xargs -d <delim> (GNU) splits standard input on the given delimiter and disables the default whitespace and quote processing. -d "\n" is a common middle ground: it keeps spaces inside each line intact while still splitting on newlines. -d also accepts escapes like \t and \0.

Common usage

Terminal
# split only on newlines, so spaces in lines survive
printf 'a b\nc d\n' | xargs -d '\n' -n 1 echo
# comma-separated input
echo 'one,two,three' | xargs -d ',' -n 1 echo

Options

FlagWhat it does
-d <char>GNU: use this character as the item delimiter
-d '\n'Split on newlines, keep spaces within a line
-d ","Split a comma-separated list into items
(GNU only)BSD/macOS xargs lacks -d; use -0 with tr instead

In CI

Prefer -0 with find -print0 for filenames, since NUL cannot appear in a path while a newline can. Reserve -d "\n" for input you control that never contains embedded newlines. On macOS runners -d is unavailable, so translate your delimiter to NUL with tr and use -0.

Common errors in CI

On BSD/macOS xargs, -d prints "xargs: illegal option -- d" because it is GNU-only. The portable substitute is "tr ',' '\0' | xargs -0 ...". Using -d "\n" still breaks on filenames that legitimately contain a newline; only -0 is fully safe there.

Related guides

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