List regular files below current, including names that may contain spaces or newlines.
Preserve each pathname as one item by using NUL delimiters before passing it to printf.
Which combination is appropriate?
find -print0 and xargs -0 use NUL as the shared item delimiter, preserving pathname boundaries that contain whitespace or newlines.
Detailed explanation
find current -type f -print0 | xargs -0 printf '<%s>\n'Correct. Both commands use NUL boundaries, so whitespace and newlines remain inside each pathname.
find current -type f -print | xargs -0 printf '<%s>\n'Incorrect. find -print uses newlines while xargs -0 waits for NULs.
find current -type f -print0 | xargs printf '<%s>\n'Incorrect. Plain xargs uses whitespace parsing and does not honor NUL boundaries.
find current -type f | printf '<%s>\n'Incorrect. printf does not consume pipeline input as command arguments by itself.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); touch "$tmp/a b"; find "$tmp" -type f -print0 | xargs -0 -n1 basename; rm -rf "$tmp"Expected result
a b(1つの引数として表示)Key points
- NUL cannot occur in a pathname
- Use -print0 with -0
- Newline delimiters are ambiguous
Notes
- Environment: GNU findutils 4.x / 一時ファイル
- Use temporary files and harmless commands for stream experiments.
- Shell redirection syntax and xargs behavior should be checked on the target shell implementation.
Foundation review
Place the operation
NUL-delimited pipelines avoid whitespace-based splitting errors for arbitrary pathnames.
Check the side effect
Create a temporary filename containing a space and verify one argument is received.