Clean up scratch without collateral damage OPS-2255

OpenShell basics · Easy · Do · about 15 min ·Linux

Lab machine

A private Linux machine with the problem already set up. Sessions last up to 60 minutes.
Mara Okafor opened OPS-2255 at 14:10task

The import job left temp files everywhere. The last person to clean up deleted the only backup of a manifest along with them.

The cleanup rule is short: delete every file directly in scratch/ whose name ends in .tmp, and nothing else.

"Last time somebody used a wildcard with tmp in the middle and took out the only backup of a manifest. List first, delete second." (Mara)

Some of the names have spaces. One starts with a dash, which rm would read as an option. One is hidden. And some files only look temporary.

Your task

Delete exactly the files directly inside scratch/ whose names end in .tmp, including the hidden one and the one that starts with a dash. Keep every other file, in scratch/ and outside it.

On the machine

  • ls -la scratch (hidden files included)
  • Files elsewhere in the lab that also end in .tmp and must stay

Timeline

Last monthrm scratch/*tmp* also deletes keepers with tmp in the middle of their names, such as the only copy of a damaged manifest.
02:30Last night's import leaves new .tmp files in scratch/.
14:10Mara asks you to clean up, by the rule this time.

Done when

  1. No file directly inside scratch/ ends in .tmp.
  2. Every other file in scratch/ is still there.
  3. Nothing outside scratch/ was removed or changed.

Hints

Hint 1

ls -la scratch shows hidden files and the exact names.

Hint 2

A glob like *.tmp matches names ending in .tmp. *tmp* matches far more.

Hint 3

rm -- scratch/*.tmp: the -- stops rm from reading a name like -rf.tmp as an option.

Hint 4

*.tmp does not match hidden files. Remove them with scratch/.*.tmp.

Show the solution

rm -- scratch/*.tmp scratch/.*.tmp, then ls -la scratch to confirm what is left.