101-500 · Question #503
When redirecting the output of find to the xargs command, what option to find is useful if the filenames contain spaces?
The correct answer is E. -print0. You've hit your Sonnet limit · resets Jun 8, 9am (UTC)
Question
Options
- A-rep-space
- B-printnul
- C-nospace
- D-ignore-space
- E-print0
How the community answered
(65 responses)- A2% (1)
- B2% (1)
- C3% (2)
- E94% (61)
Explanation
You've hit your Sonnet limit · resets Jun 8, 9am (UTC)
Topics
Community Discussion
9The correct answer is E, -print0. The core problem is that xargs splits input on whitespace by default, so a filename like "my report.txt" gets treated as two separate arguments, "my" and "report.txt," which breaks the command entirely. The -print0 option tells find to terminate each filename with a null character (ASCII 0) instead of a newline, and you pair it with xargs -0 on the receiving end so xargs knows to split on nulls rather than spaces. Think of it as a handshake: find -print0 speaks null-delimited, and xargs -0 listens null-delimited. The other options are distractors, none of them exist as real find options, so if you see -printnul or -nospace on the exam, eliminate them immediately.
E is correct. The -print0 option tells find to separate filenames with a null character instead of a newline, and you pair it with xargs -0 on the receiving end so filenames containing spaces are treated as single entries and not split incorrectly.
E is the right one, -print0 makes find separate filenames with null characters instead of newlines, so xargs -0 can handle spaces in filenames without choking.
E is right. find -print0 outputs filenames separated by null characters instead of newlines, and you pair it with xargs -0 on the receiving end so filenames with spaces or other weird characters do not get split into separate arguments.
The option -print0 is your answer, and it pairs with xargs -0 on the receiving end, which is the part they leave out of the question and what trips people up in practice. I'd argue -printnul looks tempting because null-terminator is exactly what -print0 uses under the hood, but that's not an actual find flag so toss it.
-print0 is correct and the xargs -0 pairing is the part worth drilling, but do not sleep on -exec either, since that sidesteps the whole null-terminator handoff and works the same way whether or not your vendor's xargs supports -0.
I blanked on this one for a solid minute because I kept second-guessing myself between B and E, but then I remembered that the null character is what separates filenames safely when spaces are involved, and -print0 pairs with xargs -0 to make that work, so E it is. I actually had a practice lab where I tried piping find results with spaces in the directory names and everything broke until my study buddy told me about -print0, so seeing this on the real exam felt like a gift.
I have been staring at this one for a while and I keep landing on B, because "printnul" reads to me as "print null," and a null character as the delimiter is exactly what you need to separate filenames safely when spaces are involved, so xargs can tell where one name ends and the next begins.
Hey Grace, your logic about null delimiters is spot on, but the flag that actually does that is -print0, which is option E, not B. Option B is something else entirely, so double-check the option list and you will see E lines up with what you are describing.