Finding a file type assuming wrong extension
You can use file
command:
$ file file.png
file.png: PNG image data, 734 x 73, 8-bit/color RGB, non-interlaced
$ mv file.png file.txt
$ file file.txt
file.txt: PNG image data, 734 x 73, 8-bit/color RGB, non-interlaced
The file
does some tests on file to determine its type. Probably the most important test is comparing a magic number (string in a file header) with pre-defined list.
You can try imagemagicks identify command: http://www.imagemagick.org/script/identify.php
Example:
$ identify rose.jpg
rose.jpg JPEG 640x480 sRGB 87kb 0.050u 0:01