alexkras.com

  • Home
  • Top Posts
  • Resume
  • Projects
  • YouTube
  • Boots to Bytes
  • About
  • Contact

Batch Rename Files in Unix Command Line

June 27, 2014 by Alex Kras 1 Comment

Sometimes the unix shell script is still the best tool for the job.

Today I needed to rename a bunch of java properties files from *.property to *.json. Ok, I needed to do more then just rename them, but it makes the example easier to assume that is all that I needed done 🙂

I wrote the following script in rename.sh file.

#!/bin/bash          
for file in *.properties; do
  mv "$file" "${file%properties}json"
done

Then I ran chmod +x rename.sh followed by ./rename.sh to run the file. Done.

It’s a small example, but it demonstrates well just how powerful bash scripts can be.

Filed Under: Uncategorized

I work for Evernote and we are hiring!

Subscribe to this Blog via Email

New posts only. No other messages will be sent.

You can find me on LinkedIn, GitHub, Twitter or Facebook.

This blog is moving to techtldr.com

Comments

    Leave a Reply Cancel reply

  1. MCATT says

    February 4, 2015 at 6:27 am

    What about renaming “hidden” files? Do you know how to get around it? I tried your method above but did’t work. Any help would be greatly appreciated. Thanks.

    Reply

Copyright © 2021 · eleven40 Pro Theme on Genesis Framework · WordPress · Log in