Best Practices from Oracle Development's A‑Team

Rename all the files in a directory to add a prefix

Mark Nelson


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?

Main Article

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).

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha