Skip to content

Mini challenge: tidy up a messy folder

Lesson 16 of 1610 min

Put everything together: make folders, move files with wildcards, delete temp files, save grep results and set permissions. A final hands-on Linux exercise.

Time to use everything at once. Your inbox directory is a mess of reports, photos, temporary files and a log. There's more than one right way to tidy it; the checklist only looks at the result.

Things you'll need:

  • mkdir -p makes a directory and any missing parents.
  • mv with a wildcard moves many files: mv inbox/report-*.txt …
  • rm deletes. Check a pattern with ls first.
  • grep PATTERN file > newfile saves the matching lines to a file.
  • chmod 600 makes a file private.

Take it one step at a time, check with ls as you go, and remember that Reset puts the folder back the way it was.

ls inbox

When you're done, you'll have used most of what a beginner needs on a real Linux machine: moving around, making, moving and deleting files, wildcards, searching, redirection and permissions.

Your turn

Tidy inbox: (1) make ~/archive/reports and ~/archive/photos; (2) move the three report-*.txt files into archive/reports and both .jpg files into archive/photos; (3) delete the .tmp files; (4) save every line of inbox/server.log containing ERROR (capitals) into ~/archive/errors.txt; (5) make archive/errors.txt private (600).

Done →