PLAINFINCH learn by building

Project: tidy the bakery's folder

You will clean up a messy shared folder by gathering photos, renaming a file and deleting junk, while keeping the important files safe.

What is the job?

The Crumb and Crust shared folder has had a year of everyone saving things wherever was nearest. Photos from the shop camera sit beside the menu, a backup of every file has piled up, one important document is called Untitled.txt, and there are folders called New Folder, temp and old stuff. Your job is to leave it in a state where anyone can find anything with one ls.

This project uses everything from the first two groups of lessons: looking around, making folders, moving and renaming, deleting safely, wildcards and find. Nothing new is introduced. The skill being practised is the order of work: look, plan, preview, act, check. Professionals tidy servers in exactly this way, and the habit is what keeps a cleanup from turning into a recovery job.

Why survey the folder before changing anything?

Because the folder never contains quite what you expect. Start with ls -a, which shows hidden files as well, and find . -type f, which lists every file in every subfolder with its path. Between them you see the whole job before you touch it.

Read the list and sort it in your head into three piles: files to keep where they are, files to move or rename, and junk to delete. Here the keep pile is menu.csv, orders-march.csv, notes.txt and the website folder. The move pile is five images and Untitled.txt. The junk is backups, an editor leftover and the .DS_Store files a Mac creates in every folder it opens.

Look out for traps. website/hero.jpg is a photo, but moving it would break the site, which expects it in website/. menu.csv.bak sits beside menu.csv, so any pattern starting menu catches both.

ls -a
find . -type f

How do you gather the photos?

Make the destination first with mkdir photos. Then preview the images at the top level. The camera used capitals, so you need three patterns: echo *.JPG *.jpg *.png. The preview prints IMG_2041.JPG IMG_2042.JPG loaves.jpg logo.png, four names, none of them the website’s picture, because a wildcard never looks inside subfolders.

Press Up, swap echo for mv, and add the destination: mv *.JPG *.jpg *.png photos/. The last argument to mv is the folder, and every name before it moves into it.

One photo is inside old stuff. Its folder name has a space, so quote the path: mv "old stuff/shop-front.jpg" photos/. Without quotes, mv would look for a file called old and another called stuff/shop-front.jpg. Tab completion inserts the backslash for you, as in old\ stuff/, which works equally well.

mkdir photos
echo *.JPG *.jpg *.png
mv *.JPG *.jpg *.png photos/
mv "old stuff/shop-front.jpg" photos/

How should a misnamed file be renamed?

cat Untitled.txt shows it is the wholesale price list for cafes. Renaming is a mv within the same folder: mv Untitled.txt price-list.txt. Choose names that describe the content, in lowercase, with hyphens for spaces. They sort well, need no quotes and behave the same on a laptop and on a Linux server.

Check the new name doesn’t already exist before you rename. mv replaces a file of the same name without asking, so renaming onto an existing price-list.txt would lose that file. ls price-list.txt first, or use mv -n, which refuses to overwrite.

How do you delete junk at every depth?

Wildcards only see one folder, and the backups are spread across two. This is a job for find. Preview first: find . -name "*.bak" prints ./menu.csv.bak and ./old stuff/specials-2025.txt.bak. Two backups, and the live menu.csv isn’t among them. Press Up and add -delete.

Repeat for the other junk. find . -name "*~" catches the editor leftover notes.txt~. find . -name ".DS_Store" catches the hidden Mac files in two folders, which a plain * would never match. Run each search alone, read it, then add -delete on the end.

You can combine tests with -o, meaning or: find . -name "*~" -o -name ".DS_Store" lists both kinds at once on a real machine; this practice terminal doesn’t support -o. Be careful adding -delete to an -o line. Without brackets it applies only to the second test, which is why two separate deletes are clearer to check.

find . -name "*.bak"
find . -name "*.bak" -delete
find . -name "*~" -delete
find . -name ".DS_Store" -delete

How do you remove empty folders safely?

Once the photo and backup have left it, old stuff holds nothing. New Folder and temp were empty from the start. find . -type d -empty lists exactly these three, and adding -delete removes them. The -empty test is your guarantee: a folder with even one file in it isn’t matched.

You could use rmdir "New Folder" temp "old stuff" instead. rmdir also refuses a folder with anything inside. Avoid rm -r for this step. It deletes a folder and everything in it, and if your survey missed a file, rm -r deletes it with no message.

find . -type d -empty
find . -type d -empty -delete

How do you check the result?

Finish with ls -a and ls photos. The top level should show menu.csv, notes.txt, orders-march.csv, photos/, price-list.txt and website/, with no dot files apart from . and .., and no backups. photos/ should hold five images. ls website should still show hero.jpg beside index.html.

The Files view beside the terminal marks what changed. Moved files show as new in photos/ and deleted in their old place; the files you kept should carry no badge. On a real computer, a quick find . -type f before and after, compared side by side, gives the same reassurance.

FigureBefore and after the tidy. Before: photos, backups, Untitled.txt, a hidden .DS_Store and empty folders mixed together. After: menu.csv, notes.txt, orders-march.csv, photos with five images, price-list.txt and website.Before and after the tidy. Before: photos, backups, Untitled.txt, a hidden .DS_Store and empty folders mixed together. After: menu.csv, notes.txt, orders-march.csv, photos with five images, price-list.txt and website.
Fifteen entries become six, plus . and ... Every photo has one home, the price list has a real name, and the files the bakery uses every day did not move.

What should you do differently on a real computer?

Make a copy first. cp -r bakery bakery-before-tidy takes seconds and makes every mistake in the tidy recoverable. Delete the copy a week later once nobody has missed anything. On a server, use the archive commands from a later lesson to make one compressed file instead.

If an AI assistant offers a one-line cleanup such as find . -type f ! -name "*.csv" -delete, break it into its search and its action. Run the search, read every path, and ask whether the list includes anything that should stay, such as the website’s picture here. A long clever line is harder to check than four short ones, and the short ones are what you will understand when you come back to the folder next year.

Field notes

  • Look at the whole folder with ls -a and find before changing anything.
  • Preview each pattern with echo before using it with mv or rm.
  • Use find for junk spread across several folders, and check its list first.
  • Finish by listing the folder again to confirm what is left.

Easy to get wrong

menu* matches the live menu.csv too. When you mean one file, name it. When you use a pattern, preview it with echo.

The space splits the path into two arguments. Quotes, or a backslash before the space, keep it whole.

Searching from . reaches website/hero.jpg too, and moving it breaks the site. Know which folders a search covers before attaching an action.

rm -r deletes whatever is still inside. The -empty test only removes folders that hold nothing.

Questions people ask

What is `.DS_Store`?

A hidden file macOS creates in folders opened in Finder, holding icon positions and view settings. It is safe to delete and useless on a server. Windows makes a similar Thumbs.db.

Why not delete everything that isn’t needed in one command?

Because one command is one chance to be wrong about many files. Separate, previewed steps let you check each list. Speed comes later, once the habits are automatic.

Should I keep backups like `menu.csv.bak` at all?

Short-term, yes: a .bak copy before editing is a sensible habit. Long-term they confuse people and wildcards. Git, covered in its own course, keeps history in a much tidier way.

What if I delete something by mistake here?

Use the reset button to start the practice terminal again. On a real machine, restore from the copy you made before the tidy, which is why that first step matters so much.

Keep going