A reader asked me simply “How to rename a bunch of files?” but left a clearly fake email address, so I couldn’t reply directly to them. Instead, I’ll reply to you, dear readers.

One can rename a bunch of files in myriad ways, using plain bash scripts, software like A Better Finder Rename (Mac OS), and tools like zmv. Most people satisfice here: they learn one way to do it that works well enough that they can perform effortlessly enough, then they just use it. I learned another way to do it in the past year and this has become my current favorite: using the bulkrename command in ranger, a file manager that feels like vim.

My Solution

  1. Open ranger on a folder.
  2. Mark the files to rename.
  3. Enter the command :bulkrename. This opens an editor with each file name on a separate line.
  4. Edit the file. The first line becomes the new name of the first file, the second line becomes the new name of the second file, and so on.
  5. Save the file and exit the editor. This opens and editor with a summary of the rename commands that correspond to the changes I made to the filenames.
  6. Save the file and exit the editor once more. This renames the files.

This allows me to bring the full power of my editor to renaming files: creating sequence numbers, matching regular expressions, whatever I need. I can even use some general algorithm to rename 90% of the files then patch the other 10% by hand. I love the flexibility of it and you might, too.

Enjoy!

Would You Rather Watch?

asciicast