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.
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 -pmakes a directory and any missing parents.mvwith a wildcard moves many files:mv inbox/report-*.txt …rmdeletes. Check a pattern withlsfirst.grep PATTERN file > newfilesaves the matching lines to a file.chmod 600makes 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 inboxWhen 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).
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)
The checklist ticks itself off as you work in the terminal: any way that gets the result counts.
Hints come one at a time, then one way to do it. Try each before the next.
What this lesson uses, in one place.
mkdir -p- Make any missing parent directories too, and don’t complain if the directory exists More on mkdir →
mv- Move or rename files and directories More on mv →
rm- Remove files or directories More on rm →
grep- Print lines that match a pattern More on grep →
>- Writes the output to a file, replacing what was in it
chmod- Change file permissions More on chmod →