back to labs
NUL-Safe xargs: Process Filenames With Spaces
MediumCommand Line Guru15-25 minThe brief
/root/case/files/ holds several files, and some names contain spaces (e.g. access log 2.txt). Write /root/scripts/tally.sh that prints TOTAL=<total lines across every file>.
The trap: ls files | xargs wc -l splits access log 2.txt into three arguments and miscounts. The fix is to separate items by NUL instead of whitespace — have find emit paths with -print0 and read them with xargs -0, so a space in a name is never mistaken for a separator.
Grading runs your script on these files and on a held-out set you have not seen, checks each total, and confirms you used a NUL-safe method (-print0 / -0). /root/case/brief.txt has a worked pipeline.
What you'll do
- Total the line counts across every file in the directory
- Survive filenames that contain spaces
- Use find -print0 piped to xargs -0
- Understand why ls | xargs is unsafe here
Hands-on lab: you work on a real Linux box in your browser, graded on the machine's actual state.
