If you use (from command line or within a script... if you need the script just ask ;) ) the command file thisimage.png
, it will tell you what image format you actually have.... Then you can rename accordingly...
This is a sample of what I get with a file with incorrect file extension .png which is really a jpg file:
user@computer:$ file logo.png
logo.png: JPEG image data, JFIF standard 1.01
Edit: Oh, ok, I was lazy before... Here's an script that will rename actual gif files that are named with .png extension to their correct extension .gif:
#!/bin/bash
for NAME in $(ls *.png); do
if [ "$(file $NAME|grep GIF)" ]; then
echo "Renaming ${NAME} to ${NAME%.*}.gif"
mv ${NAME} ${NAME%.*}.gif
fi
done
This is what probably happens. The application designated to open files with the file types you mention, is the same across all of those. .gif, .jpg, .png: these are all handled by EOG (GNOME's Eye Of Gnome). I suspect this application does not determine the file type based on the extension, rather it seeks for the magic number.
Note that the behavior of EOG may very well be exceptional, and also beware that no actual conversion is done. It's just that Linux applications tend to rely on different detection methods than file extensions, though many modern desktops actually look for the file extension to determine what application to open, since this method is probably quicker.
This all may apply to Ubuntu, Windows is a completely different story. Explorer practices a behavior by default that cuts off the file extension from the filename. This way, a file named "document.pdf" will show as "document", and renaming it to "document.dvi" will actually be processed as "document.dvi.pdf". Viruses sometimes exploit this "feature" by making the user believe they are opening a .jpg, while in reality they are being tricked into running a malicious exe!
To be really sure about filetypes, there is a command called file
that shows you detailed file information.
From my personal experience, I can tell that, at least on my system, EOG cannot be tricked into recognizing a renamed image file. You must be doing something different than I do.
Best Answer
This will do the job for you.
rename 's/.m4b$/.m4a/' *.m4b
For a test run you can use this command:
rename 's/.m4b$/.m4a/' *.m4b -vn
-v
means "verbose" and it will output the names of the files when it renames them.-n
will do a test run where it won't rename any files, But will show you a list of files that would be renamed.