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 some 200+ files named something in line with "DSC01852.JPG.jpg". I would like to remove the file extension so the result becomes "DSC01852.JPG".

Any suggestions? I looked at the mv command but couldn't quite figure out how to write the correct command.

share|improve this question

migrated from May 20 '13 at 16:17

This question came from our site for professional and enthusiast programmers.

up vote 5 down vote accepted

If these files are all in the same directory you can rename them like this:

for f in /some/dir/*.JPG.jpg; do
  mv "$f" "${f%.*}"

${f%.*} removes shortest text matching the pattern .* (a dot followed by arbitrary text) from the end of the variable $f (in this case the file name), thus producing commands like the following:

mv "/some/dir/DSC01852.JPG.jpg" "/some/dir/DSC01852.JPG"
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.