{"id":"code-col-bash-dry-run-rename-photos","audience":"college","category":"coding","track":"coding","technique":"constraints","title":"Write a dry-run rename loop for your lab's photo folder","free":false,"task":"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.","materialLabel":"The folder listing and notes (attached to your prompt automatically)","material":"$ pwd\n/home/lab/field-2026/plots\n$ ls -1\nPlot 07 Oct3.JPG\nplot 07 oct4.jpg\nPlot 12 Oct3.JPG\nplot_12_oct4.jpg\nREADME.txt\nnotes from Sept.docx\nsoil samples.csv\n\nNotes from the lab Slack (#field-2026):\n\nDr. Okafor: \"Before anyone renames things in the shared folder, post\nthe exact commands in the channel first. Last spring someone's rename\noverwrote three days of photos because two names collided.\"\n\nPriya: \"The analysis script expects lowercase names with underscores,\nlike plot_07_oct3.jpg. Extension should be lowercase too.\"\n\nMe: Machine is Ubuntu 24.04, bash 5.2. No 'rename' (perl) installed and\nI don't have sudo.\n\nOnly the photos should change. README.txt, the docx and the csv stay as\nthey are.","rules":[{"type":"codeBlocks","count":1},{"type":"maxCodeLines","max":9},{"type":"maxProseWords","max":25}],"mistakes":[{"title":"Actually renaming","why":"Asked to rename, the AI writes a loop that moves the files right away.","fix":"Say: \"Dry run: only echo the mv commands; don't run them.\"","checks":["r0"]},{"title":"Risking overwrites","why":"Plain mv silently replaces a file with the same name, like last spring.","fix":"Add: \"Print mv -n -- \\\"old\\\" \\\"new\\\" with quotes.\"","checks":["r1"]},{"title":"Missing files or noise","why":"The AI may only match .jpg, or print a no-op line for plot_12_oct4.jpg.","fix":"Add: \"Cover .jpg and .JPG; skip names that wouldn't change.\"","checks":["r1","r2"]},{"title":"A tutorial","why":"The AI explains every line and suggests installing rename.","fix":"Add: \"One code block, at most 9 lines, no text.\"","checks":["codeBlocks","maxCodeLines","maxProseWords"]}],"promptHints":[{"label":"Asks for a dry run","patterns":["dry.?run","echo","print (the )?commands","don'?t (run|move)"]},{"label":"Rules out overwriting","patterns":["-n","no.?clobber","overwrit"]},{"label":"Covers both extensions","patterns":["\\.JPG","uppercase extension","both"]},{"label":"Gives the naming rule","patterns":["lowercase","underscore"]},{"label":"Skips unchanged names","patterns":["skip","unchanged","already"]}],"hint":"With shared data, a dry run you can read first beats a clever one-liner. Tell the AI to only print commands, which flags to use and which files to skip.","rubricLabels":["Only prints the commands (e.g. echo mv ... or printf), so nothing is actually moved","Each printed command is mv -n -- \"old\" \"new\" with both names quoted, and the loop covers both *.jpg and *.JPG","The new name is lowercase with spaces replaced by underscores (e.g. ${f,,} plus ${new// /_} or tr), and files whose name wouldn't change are skipped"]}