Mass rename files in UNIX

Several of my Rails projects surface a RESTful API. I use integration tests to verify that the API calls work as expected. I also version my API calls so I can easily adapt the API to new circumstances while maintaining backwards compatibility.

To move to a new API version, I copy all of the existing integration tests and rename their prefix to the new version. Instead of renaming the files by hand, there is a nifty UNIX command that handles it for me. For example, to rename all the “v2_*.rb” files to “v3_*.rb” I would type:

for file in *; do mv "$file" "v3_${file#v2_}"; done

One thought on “Mass rename files in UNIX

  1. Mass renaming of files can vary depending on what platform and system you’re on. If you’re on Unix, and more specifically Unix, the following techniques should be available to you.

    If you’re using RedBrick then both mmv and rename are available to you.

    In this scenario, we are going to try and rename all .php files in the current directory so they have a .gif extension

    WARNING: always backup your files

    File Renamer

Comments are closed.