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 an Architect (an "IC6") in the Fusion Middleware Central Development Team at Oracle. Mark's job is to make Fusion Middleware easy to use in the cloud and at home, for developers and operations folks, with special focus on continuous delivery, configuration management and provisioning - making it simple to manage the configuration of complex environments and applications built with Oracle Database, Fusion Middleware and Fusion Applications, on-premise and in the cloud. Before joining this team, Mark 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 Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s