Library › Coding AI › College students
Write a dry-run rename loop for your lab's photo folder
Practice: Setting limits and rules. About 5 minutes.
About this exercise
Your research lab wants the plot photos renamed to lowercase with spaces turned into underscores, but the PI wants a dry run first: the loop must only print the commands, never move anything. Print each as mv -n -- "old" "new" (no overwriting), cover both .jpg and .JPG, and skip files whose name wouldn't change. Exactly 1 code block of at most 9 lines (bash 5), under 25 words of text.
Common mistakes when you ask AI for this
- Actually renaming. Asked to rename, the AI writes a loop that moves the files right away. Try: Say: "Dry run: only echo the mv commands; don't run them."
- Risking overwrites. Plain mv silently replaces a file with the same name, like last spring. Try: Add: "Print mv -n -- \"old\" \"new\" with quotes."
- Missing files or noise. The AI may only match .jpg, or print a no-op line for plot_12_oct4.jpg. Try: Add: "Cover .jpg and .JPG; skip names that wouldn't change."
- A tutorial. The AI explains every line and suggests installing rename. Try: Add: "One code block, at most 9 lines, no text."
What a strong prompt includes
- Asks for a dry run
- Rules out overwriting
- Covers both extensions
- Gives the naming rule
- Skips unchanged names
Related exercises
- Add a cron line that matches the others in a crontab (Coding AI · Product managers)
- Add dark mode by overriding your existing CSS variables (Coding AI · Software developers)
- Add input checks to your number guessing game (Coding AI · High school students)
- Add input validation to a Java method with exact messages (Coding AI · Software developers)
- Add labels to a signup form without rewriting the page (Coding AI · High school students)