[xargs] Read NUL-delimited filenames with xargs -0

Created on November 30, 2026

Use -0 to treat NUL as the input delimiter. Spaces or newlines in a filename can then remain part of the same argument.

printf '%s\0' 'apple pie.txt' 'orange.txt' |
  xargs -0 -n 1 printf 'file=%s\n'
file=apple pie.txt
file=orange.txt

printf '%s\0' appends a NUL to each input string. -n 1 passes one item to each invocation.

Use find -print0 to emit filenames in the same format.

find . -type f -print0 |
  xargs -0 -n 1 printf 'file=%s\n'

References

Shell command xargs