Bulk edit filenames using shell

Unix/linux command to remove specific matching text from all files. In this case, I had a list of tiles that had -defaults.properties suffix. I wanted to rename them all so that they had just .properties suffix instead. For example, if a file was named connection-defaults.properties, I wanted it to be renamed to connection.properties

As usual, rather than wasting my time and doing it manually 100 times, I set myself to find an automated way of doing it. And sure enough, I found it!

Here it is:

The above command finds all files that end with -defaults.properties. For each file that match that criteria, we then rename it to a name that has -defaults stripped out. To strip out the name, we use sed command and to rename we use mv command.

Tested on mac running oh-my-zsh.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.