4

Searching, googling, I could not find any information about file types recognized by file.

For example, an *.mp4 file is identified as "ISO Media" (while being able to play with VLC normally). This is not 100% clear, it somehow leaves me to wonder whether it's a correct detection or the file is confused for ISO image. (Either because e.g. the sample is somehow corrupted, or, just that the algorithm is not 100% accurate for all types.)

My problem is that I need to set up some rules for switching based on file type. I have set created a sample file set, but I cannot collect enough samples of all types which I need to be recognized by my code. And the real set will probably be really huge.

It would be enough for me if I could read some comments to use as a reference to those types which are not so obvious. But to my surprise, I could not find any useful information. Most of my searches ended on magic file format specification, which is not really helpful to me. I'm interested in the magic file which is distributed with, say, Debian.

4
  • 2
    Tried file --mime-type?
    – alex
    Commented Aug 3, 2011 at 11:47
  • Have you looked at TrID? Commented Aug 3, 2011 at 17:29
  • @Amazed: TrID looks interesting, however it's free only for non-commercial use--my project is of a commercial character :-/ Commented Aug 3, 2011 at 18:22
  • @alex: Yes, I have, and I can't see more documentation than for file. file --mime is tempting (has way nicer output), but unfortunately it's not option for me as it does not recognize e.g. PE32 executable. (Thanks though, for "forcing me" to try it, maybe a combination of these methods will come handy in future.) Commented Aug 3, 2011 at 18:42

2 Answers 2

3

The type detection information isn't actually embedded in the file program, the file program just reads the magic file and then searches the signatures in that file to see what matches.

The magic file exists both as a compiled version, magic.mgc, and as the original source that is human readable and is just called magic. On my Fedora based systems these can be found at:

/usr/share/misc/magic
/usr/share/misc/magic.mgc

More information on the format of the file can be found in the magic(5) manual page.

5
  • 1
    On Debian it seems only the compiled .mgc is present - the magic/ dir is empty.
    – jw013
    Commented Aug 3, 2011 at 10:22
  • 1
    Well it isn't a directory, it's a file. On Ubuntu /usr/share/misc/magic seems to be a symbolic link to /usr/share/file/magic and both that and magic.mgc are provided by libmagic1.
    – TomH
    Commented Aug 3, 2011 at 10:48
  • Oh I see. It's still an empty directory on Debian (same symlink even, just directory not file).
    – jw013
    Commented Aug 3, 2011 at 10:51
  • 2
    According to Debian users' mailing list, the source to magic file is available only with src package, ie. file_5.04.orig.tar.gz/magic/Magdir/. There are multiple files, I'd guess that on Fedora there are approx. the same joined into one. Commented Aug 3, 2011 at 14:53
  • @AloisMahdal The source of the file package also contains the source of the magic.mgc file, in the magic/Magdir directory. There are even comments (sometimes). Commented Aug 4, 2011 at 0:10
2

Well I don't know if the sourcecode for the file command is human readable.

But if you would like to find out why your mp4 is recognised as a iso I would start to read the sourcecode.

6
  • AFAIK the sourcecode of the commend does not contain this information as (since very long long time ago), file reads this information from external file -- magic.mgc. But that file is not human-readable--it's a binary format with come null bytes etc. Commented Aug 3, 2011 at 10:09
  • And the mp4 was just an example, there is a lot more types I would like to be more certain about. Thanks for your tips, though... :) Commented Aug 3, 2011 at 10:12
  • Oh, that is a strange solution. So my answer is not really helpful at all, I'll leave it be for reference thou.
    – Johan
    Commented Aug 3, 2011 at 10:13
  • Actually this answer is still helpful - the pre-compiled magic source files should be distributed with along with file, so you'll probably find them in the source packages.
    – jw013
    Commented Aug 3, 2011 at 10:21
  • @jw013 - You are right in file_5.04.orig.tar.gz there is a dir with some interesting stuff magic/Magdir/. It looks like the input for the magic file.
    – Johan
    Commented Aug 3, 2011 at 10:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .