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.
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.
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.
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.
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 / 一時ファイル
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.