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 a lot of folders with a lot of files and maybe more folders with more files, where some files lost their extension. I believe they are all jpgs, but I could be wrong. Any ideas how to re-add the extensions to all these files without doing it one by one?

I can do it on Windows 7 or Ubuntu 8.10.

share|improve this question
This question will probably have an answer for you, as it is a bit similar :… – Gnoupi Aug 26 '09 at 20:11
Did you check that you haven't turned off the display of the extension on those folders before embarking on the rename? Basic question I know, but you never know. – ChrisF Aug 26 '09 at 20:16
ChrisF, yes, I did. Thank you. – Pablo Aug 27 '09 at 5:38

You can do it through cmd on windows.

rename * *.jpg

To apply to nested folders, you can use;

for /r %x in (*) do rename "%x" *.jpg

share|improve this answer
Will that work recursively in all folders? – Pablo Aug 26 '09 at 19:03
The command prompt still has its uses :) Yeah DOS! – Stewbob Aug 26 '09 at 19:06
It will not - you'll need to use the 'for' command as demonstrated here:… – Jeffrey Aug 26 '09 at 19:14
Thanks Jeffrey; I've not come across "for" before! That's pretty nifty. I added that to the solution body. – RJFalconer Aug 26 '09 at 20:20
+1 for a nice answer that didn't involve installing other operating systems or a heap of other programs. – Joey Aug 26 '09 at 21:42
up vote 3 down vote accepted

I did it this way

find . -type f -iregex ".*[^\(\.jpg\)]" -exec mv "{}" "{}.jpg" ";"
share|improve this answer
Nice. FWIW, a simpler method than -iregex is to use the negative of a name match: find . -type f \! -name '.jpg' (...). Also, I try always to use an absolute path (*/bin/mv) when using find/-exec. – NVRAM Sep 28 '09 at 18:05

If using powershell is an option, then this post from SO should be exactly what you want.

share|improve this answer

On Linux

ls | while read file ; do mv $file $file.jpg; done

On Windows

I like to use Rename4u which is a freeware utility.

share|improve this answer
Just got to be careful not to append a .jpg extension to IMAGE001.jpg – Jeffrey Aug 26 '09 at 18:52
Wouldn't the Linux version add the extension to all the files? Not all the files are missing the extension. – Pablo Aug 26 '09 at 19:00
@J Pablo, .jpg.jpg still opens as a jpg ;) In windows I'd do: ren * *.jpg but you could hack something together with a batch file to only do that if something didn't have an extension - I'm too lazy, myself. If it works, it works, right? – Phoshi Aug 26 '09 at 20:32

Extension Renamer does the job.

share|improve this answer

For Linux (or MSWindows w/CygWin)

If you wish to only add a suffix to files that are actually JPEGs, try this:

$ find . -type f  ! -name '*.jpg'  -print | while read f
> do case "$(file "$f")" in
>    *JPEG*) mv -iv "$f" "$f.jpg" ;;
>    esac
> done

Which will:

  1. Print paths that are files w/o a _*.jpg_ suffix (find),
  2. Check those files' contents (file $f),
  3. For JPEG files, rename them with a _*.jpg* suffix.
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.