Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a folder with images named:


How do I rename them to the following?


I have tried mv "pic*-2.png" "pic*.png" but keep getting errors.

share|improve this question
up vote 10 down vote accepted

This will delete the first -2 found in each filename:

for f in pic*-2.png; do
  mv "$f" "${f/-2/}"

To test it, just prepend echo to the mv line.

share|improve this answer
perfect! thanks – user114558 Jun 17 '11 at 8:56

You need the appropriately named 'rename' command!

Try something like this:

rename 's/(pic\d+)-\d\.jpg/$1.jpg/' pic*.jpg

It takes a perl regular expression as the first argument, so your pattern-matching and manipulation options are pretty extensive. See the rename(1) man page for full details.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.