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.

Finding classes in jar/war files

Recently I was out looking for classes that were present in my Web Application Archive (WAR) file. Why? Well, I was out combating Jar Hell. As I am allergic to doing things manually, here’s a small command I constructed to help me find classes within jar files:

The above command prints out class file as well as the name of the jar file that class is present in. If you’re looking just for the path where the classes are present, you can just run: