Rename all the files in a directory to add a prefix

This is a bit off topic, but it is something I frequently want to do!

When I am producing a new post I usually end up with a number of images that I want to include.  I normally create these in PowerPoint, and then save them as PNG images.  This gives me a directory with a bunch of files called Slide1.png, Slide2.png, etc.

I like to add a prefix to make it easier and cleaner and ensure there are no name clashes, but how to do this quickly and easily?

This is the fastest was I have found to do this:

for file in $(echo *.png); do mv ${file} ubuntu.${file}; done

I run this in a terminal window, and it does the job, leaving me with a bunch of files call ubuntu.Slide1.png, ubuntu.Slide2.png, etc. (in this case).

About Mark Nelson

Mark Nelson is a Developer Evangelist at Oracle, focusing on microservices and messaging. Before this role, Mark was an Architect in the Enterprise Cloud-Native Java Team, the Verrazzano Enterprise Container Platform project, worked on Wercker, WebLogic and was a senior member of the A-Team since 2010, and worked in Sales Consulting at Oracle since 2006 and various roles at IBM since 1994.
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

Leave a comment