{"slug": "how-to-bulk-rename-files-safely-on-windows-macos-and-linux", "title": "How to bulk rename files safely on Windows, macOS and Linux", "summary": "A developer published a hands-on guide to bulk renaming files safely on Windows, macOS and Linux, covering built-in tools like File Explorer, Finder, PowerShell and the shell, plus Microsoft's free PowerToys PowerRename. The guide warns that naive renumbering loops can silently overwrite files on Linux and macOS, and recommends two-phase renames, case-insensitive collision checks and dry-run previews. It also introduces TidyBatch, a free open-source command-line tool the author built around those rules, which previews by default and keeps a journal for one-command undo.", "body_md": "Renaming hundreds of files takes seconds. Undoing a bad rename can be impossible. Here is how to do it on Windows, macOS and Linux without losing anything, with the free built-in options first.\n\n*Disclosure: this article was written with AI help (Claude), and every command below was run before publishing; the output shown is real. We make TidyBatch, a free command-line tool mentioned at the end, which has a paid Pro version (9 €).*\n\n**File Explorer.** Select the files, press F2, type a name and press Enter. Windows names them `Name (1)`, `Name (2)`, … Fine for quick numbering, but no preview and no patterns.\n\n**PowerToys PowerRename** (free, from Microsoft). Install [Microsoft PowerToys](https://learn.microsoft.com/en-us/windows/powertoys/powerrename), select files, right-click, *Rename with PowerRename*. Live preview, regular expressions, numbering and date variables. Ctrl+Z in Explorer undoes the batch right afterwards.\n\n**PowerShell.** Add `-WhatIf` to preview:\n\n```\n# Preview: lowercase all .jpg names and replace spaces with underscores\nGet-ChildItem -File *.jpg | Rename-Item -NewName { $_.Name.ToLower() -replace ' ', '_' } -WhatIf\n\n# Looks right? Run the same line without -WhatIf\nGet-ChildItem -File *.jpg | Rename-Item -NewName { $_.Name.ToLower() -replace ' ', '_' }\n```\n\nWith two files, `Holiday Photo.JPG` and `Beach Day.JPG`, the `-WhatIf` line prints:\n\n```\nWhat if: Performing the operation \"Rename File\" on target \"Item: …/Beach Day.JPG Destination: …/beach_day.jpg\".\nWhat if: Performing the operation \"Rename File\" on target \"Item: …/Holiday Photo.JPG Destination: …/holiday_photo.jpg\".\n```\n\n`Rename-Item` refuses to replace an existing file (`Rename-Item: The file '…/a_b.jpg' already exists.`). Good, but in a long batch a few files fail halfway through, so read the red errors.\n\n**Finder.** Select the files, right-click, *Rename…*. *Replace Text*, *Add Text* or *Format* with a counter, with an example of the result. *Edit → Undo* straight away if it is wrong.\n\n**Terminal.** Use `mv -n` (no-clobber) and print the commands before you run them:\n\n```\n# Preview (echo only), then remove \"echo\" to run\nfor f in *.JPG; do echo mv -n -- \"$f\" \"${f%.JPG}.jpg\"; done\nmv -n -- IMG_1.JPG IMG_1.jpg\nmv -n -- Photo One.JPG Photo One.jpg\n```\n\nThere are two different `rename` commands (Perl and util-linux) with different syntax. Run `rename --version` to see which you have. The util-linux one only prints the plan with `-v`:\n\n``` php\n# Perl rename (Debian/Ubuntu \"rename\" package): spaces -> underscores\nrename -n 's/ /_/g' *\n# rename(My Trip 2.jpg, My_Trip_2.jpg)\n# rename(Photo One.jpg, Photo_One.jpg)\n\n# util-linux rename (Arch, Fedora…): replace the first \"IMG_\" with \"photo_\"\nrename -nv IMG_ photo_ *\n# `IMG_1.JPG' -> `photo_1.JPG'\n```\n\nSay you renumber `1.txt, 2.txt, 3.txt` to `2.txt, 3.txt, 4.txt`. A simple loop renames `1.txt → 2.txt` first. On Linux and macOS a plain `mv` or Python's `os.rename` **overwrites the original 2.txt without warning**. On Windows it fails instead, leaving the folder half renamed.\n\nThe fix is two phases: move every file to a temporary name, then to its final name. Or rename into a new, empty folder. A related trap: on Windows and macOS `Photo.JPG` and `photo.jpg` are the *same* file, so collision checks must ignore case.\n\n[TidyBatch](https://tidybatch.github.io/?utm_source=devto&utm_campaign=tidybatch) is a free, open-source command-line tool (we made it) built around these rules. It previews by default, renames in two phases, checks collisions without case, and keeps a journal so you can undo with one command, even after an interrupted run. Install it with `pipx install tidybatch`, or try it without installing with `uvx tidybatch`. On a folder with three files:\n\n``` php\n$ tidybatch rename Downloads --slug --lower\n  Café Menu.txt          ->  cafe_menu.txt\n  Holiday Photo 1.JPG    ->  holiday_photo_1.jpg\n  Report Final (v2).PDF  ->  report_final_v2.pdf\n\n3 file(s) would change.\nDry run: nothing was changed. Add --apply to do it.\n\n$ tidybatch rename Downloads --slug --lower --apply\n  Café Menu.txt          ->  cafe_menu.txt\n  Holiday Photo 1.JPG    ->  holiday_photo_1.jpg\n  Report Final (v2).PDF  ->  report_final_v2.pdf\n\n3 file(s) will change.\nDone. To revert: tidybatch undo \"Downloads\"   (journal: journal-20261103-010602-321629.json)\n\n$ tidybatch undo Downloads\nRestored 3 file(s), skipped 0. Journal: journal-20261103-010602-321629.json\n```\n\nIt runs locally and needs no account. `rename` and `undo` are free; the paid Pro (9 €) adds `organize` and `dedupe`. More guides: [tidybatch.github.io/guides](https://tidybatch.github.io/guides/?utm_source=devto&utm_campaign=tidybatch). Code: [github.com/tidybatch/tidybatch](https://github.com/tidybatch/tidybatch).\n\nIf you only use Windows and like clicking, PowerRename is excellent and free. TidyBatch is for when you want the same command on every OS, in scripts, with an undo that survives closing the window.", "url": "https://wpnews.pro/news/how-to-bulk-rename-files-safely-on-windows-macos-and-linux", "canonical_source": "https://dev.to/stillwatertools/how-to-bulk-rename-files-safely-on-windows-macos-and-linux-i96", "published_at": "2026-11-03 01:07:53+00:00", "updated_at": "2026-11-03 01:22:38.974496+00:00", "lang": "en", "topics": ["developer-tools"], "entities": ["Microsoft", "PowerToys", "PowerRename", "PowerShell", "Finder", "TidyBatch"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/how-to-bulk-rename-files-safely-on-windows-macos-and-linux", "markdown": "https://wpnews.pro/news/how-to-bulk-rename-files-safely-on-windows-macos-and-linux.md", "text": "https://wpnews.pro/news/how-to-bulk-rename-files-safely-on-windows-macos-and-linux.txt", "jsonld": "https://wpnews.pro/news/how-to-bulk-rename-files-safely-on-windows-macos-and-linux.jsonld"}}