Signal9Signal9 — home
online
back to labs

Xargs: Act on a List of Files

MediumCommand Line Guru10-15 min
The brief

A cleanup manifest lists files to remove — but the list is stdin, and rm doesn't read stdin. That's exactly the gap xargs fills: it reads items on stdin and builds them into arguments for a command.

Under /root/workspace there's a pile of build artifacts, and /root/workspace/cleanup.txt names the ones to delete (one path per line). Delete exactly those, and only those, by feeding the manifest through xargs:

xargs rm < /root/workspace/cleanup.txt

Some files are NOT in the manifest — they must survive. Grading checks that every listed file is gone and every unlisted file remains, so a blanket rm won't pass.

Safety tip for the real world: filenames with spaces break naive xargs — pair find -print0 with xargs -0. This manifest has none, so the simple form is fine here.

What you'll do
  • Feed the cleanup manifest through xargs to delete the listed files
  • Leave every file not named in the manifest untouched

Hands-on lab: you work on a real Linux box in your browser, graded on the machine's actual state.