Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux file utility magic.mgc database get content

Tags:

file

linux

unix

I write project where I need to identify certain file formats. For some formats I have found signatures that I use for identifying easily (mp3, ogg), with another formats I have a big problem (like MPEG ADTS) - I just cannot find what kind of signature can be used for it.

I found out that File utility for Linux environment can do it. I tried to search it in source code, but I've found nothing.

I found that file utility holds its database in magic.mgc file. But it's hold in binary form. It looks like: enter image description here

Does someone perhaps know how to find that database in plain text format?

like image 338
Tebe Avatar asked Aug 31 '25 04:08

Tebe


1 Answers

That utility isn't a Linux-specific utility; it's the version of the UN*X file command originally written by Ian Darwin. The binary .mgc file is generated from a bunch of source files.

Your Linux distribution probably has a source code package for it; where you get that package, and how you install it, depends on which distribution you're using.

The source files from which the .mgc file was generated might also be available on your distribution without installing the source package for file; if so, you could use the file command to generate it, using the -C flag. I don't see them anywhere obvious on my Ubuntu 12.04 virtual machine, so that might require some other package to be installed (file itself is installed). (On OS X, they're in the directory /usr/share/file/magic.)

Alternatively, you could download the standard version of that file (which might have been modified by your distribution, so you might not want that version) and modify and build it.

Note that, on some versions of UN*X systems, the bulk of the work done by the file command is done in library routines in the "libmagic" library; see whether your distribution has that or can install it (try, for example, man libmagic) and whether it can do the job for you.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!