Home » Questions » Computers [ Ask a new question ]

Add the extension, jpg, to a lot of files

Add the extension, jpg, to a lot of files

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?

Asked by: Guest | Views: 49
Total answers/comments: 3
Guest [Entry]

"I did it this way

find . -type f -iregex "".*[^\(\.jpg\)]"" -exec mv ""{}"" ""{}.jpg"" "";"""
Guest [Entry]

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

"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:

Print paths that are files w/o a *.jpg suffix (find),
Check those files' contents (file $f),
For JPEG files, rename them with a _.jpg suffix."