Skip to content

Mini challenge: tidy up a messy folder

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

Lesson 16 of 1610 minSkip to the terminal ↓

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 task

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).

  • Make archive/reports and archive/photos (not done yet)
  • Reports moved into archive/reports (not done yet)
  • Photos moved into archive/photos (not done yet)
  • The .tmp files are gone (the rest stays) (not done yet)
  • The ERROR lines are in archive/errors.txt (not done yet)
  • archive/errors.txt is 600 (not done yet)

Lesson 16 of 16.

learner@sandbox: ~bash (practice)
Note: Practice shell for this lesson. Type a command and press Enter (help lists them all).