For example I have picture1.JPG then another user of my computer change the extension from picture1.JPG to picture1.PNG, I am sure that in most cases it will work. My question is this, is there a way to detect if a files extension has been modified?
Asked
Active
Viewed 685 times
1
Cary Bondoc
- 336
- 2
- 6
- 19
-
Practically outside windows, file extensions matter little. – Journeyman Geek Nov 23 '15 at 02:26
-
duplicate question here https://superuser.com/questions/274734/is-there-a-tool-that-can-determine-the-file-type-from-containing-data?noredirect=1&lq=1 – ABDO Apr 26 '17 at 07:54
2 Answers
2
The file program examines the contents of files, showing their actual type (with occasional misses). If you are using a Unix-like system, you probably already have it installed (there is a POSIX description of it, for instance). For Windows, there is a port in GnuWin32 (a little old, but better than nothing).
The program lists each filename, along with the types. All you have to do (with a script would be nice) is to look for mismatches between the two (filename versus description of its type).
Here is some sample output to illustrate:
escher03.jpg: JPEG image data, JFIF standard 1.02
snakes.jpg: JPEG image data, JFIF standard 1.01
sphere.gif: GIF image data, version 87a, 1120 x 832
spirals.jpg: JPEG image data, JFIF standard 1.00, comment: "U-Lead Systems, Inc."
square_l.gif: GIF image data, version 87a, 634 x 668
st_peter.gif: GIF image data, version 87a, 640 x 480
Thomas Dickey
- 8,632
- 3
- 22
- 31
2
Just to give you another alternative if you need to work only with images. You can use the command identify, which belongs to ImageMagick:
$ identify stellarium-000.png
stellarium-000.png PNG 1364x728 1364x728+0+0 8-bit sRGB 248KB 0.000u 0:00.000
skytux
- 388
- 2
- 6