Image Processing Reference
This approach does not transfer well to other platforms, so the more recent versions
of Mac OS also use the file extension to identify what kind of file it is. This is how most
other operating systems determine the file type.
In the Unix command-line environment, the file utility can be used to determine the
kind of file you are inspecting. This is rather clever because it looks at the beginning of the
file and works out the file type from the content. The file extension is irrelevant because
Unix considers the entire file name, the dot, and the file extension to be a single string of
characters. Here is an example of how the file utility is used from the Unix command line:
$ file 0007.jpg
0007.jpg: JPEG image data, JFIF standard 1.02, resolution (DPI), 300 × 300
$ file 0010.ai
0010.ai: PDF document, version 1.4
$ file “Interesting article”
Interesting article: ASCII mail text, with very long lines, with CR line
$ file “tivo_1.pdf”
tivo_1.pdf: PDF document, version 1.3
The file utility uses a table of information stored in a special file called magic .
If you use the Unix manual pages, the help file will tell you where this magic file lives
so you can go and look at it. On Mac OS X it lives in the directory path at
/usr/share/file/magic , which is a location you cannot normally get access to with
the GUI interface because those sorts of things are hidden away in order not to frighten
the unwary user.
Learning some power-tool tricks with the command-line interface is a very worth-
while skill. You need not become tremendously adept at it before it becomes very useful.
If you have a collection of files of unknown types, you might be able to write some kind
of shell script and then go through them and add the correct extension.
The Unix file utility lets you manually select an alternative magic file. You can use
the one that is provided to tell you what the mime type of a file is or you can roll your own
and provide some custom file identification. Given that you have a file called fred in your
directory, the following command will report its mime type to you as long as it is a known
type of file.
file fred -m /usr/share/file/magic.mime