7

I love file. I use it multiple times a day. I love it so much that I install Cygwin on my Windows machines just so I can use it. Anyway, in going through older files on my system, I find there are many files that just report "data" from the file command. Understandably.

Some of these files however do have an indicator in their header of what kind of file they are, but are not found in the magic file database yet. My questions are three-fold:

  1. Is there an online repository of magic file definitions that I can use to supplement or update the default ones that came with my OS? (My folder /usr/share/file/magic shows the most recent entry as almost one year ago, and I know people are continually updating these definitions)
  2. How can I submit a new definition that I've developed so that the rest of the *nix community can benefit? The online repo?
  3. Is it as simple as dropping the magic definition file in the folder, and my OS will magically find it, or do I have to somehow rebuild the definition library? Do I have to do anything with the magic.mgc file, or just the folder of individual definitions?

Thank you ahead of time for your help.

4
  • file is fully scriptable - you can put your own magic tests in script files and specify these on the command line with -[mM] switches. See the spec.
    – mikeserv
    Jul 2, 2015 at 18:45
  • To answer question #3, it seems like compiling your own definitions is addressed here: stackoverflow.com/q/7236191/695772
    – tralston
    Jul 2, 2015 at 19:06
  • After testing my magic file, I tried file -C -m myfile and it produced myfile.mgc and magic.mgc. I tried copying these files to ~/.magic, and /usr/share/file/magic. When I re-run the file command on my file, it still reads "data". How can I tell the system to use my new definition?
    – tralston
    Jul 2, 2015 at 19:22
  • 1
    @tralston You should've copied the compiled version to ~/.magic.mgc not to ~/.magic; or simply copied the myfile text definition to ~/.magic.
    – user313992
    Mar 9, 2019 at 13:00

2 Answers 2

3

In the past I've had changes included in the magic file by submitting a Debian bug report but it's probably faster to submit them upstream directly.

In answer to your questions:

  1. The latest released source can be found here - there's a link to a mirror of the source repo there.
  2. Yes, I believe either submitting a bug report or emailing the mailing list should be all that's needed to add a file definition.
  3. You can create your own magic file and point file file to it by using the -m option.
3
  • 1.) I actually found that a little while ago too. But how do I update my system with the latest repo? Should I just checkout the repo and copy the files to my system? Or is there an apt-get way of pulling the repo? 3.) Is there a way to do it such that I don't have to always include the -m argument? That's what I mean in the question comments by it compiling but not recognizing my new definition.
    – tralston
    Jul 4, 2015 at 4:01
  • As noted above copy the the magic file to ~/.magic and/or the magic database to ~/.magic.mgc and your magic file should be picked up without having to supply the -m parameter. That is unless you are running macOS Catalina (or possibly some other macOS release). Nov 2, 2022 at 21:37
  • Regarding the question of getting the newest release of the magic files: I'm not sure if this is such a good idea because the syntax of the magic files might change between releases (at least the format of the database can be incompatible) so it might be better to grab the complete release instead just the magic files considering that releases are rather frequent. Nov 2, 2022 at 21:46
2

About your question 3. :

Try adding your custom definitions to /etc/magic. It will be used alongside the pre-compiled magic.mgc file.

If it doesn't work, check with

file --version

On my Ubuntu 16.04 system, it reports:

file-5.25
magic file from /etc/magic:/usr/share/misc/magic

So it uses both the /etc/magic text file, and the pre-compiled /usr/share/misc/magic.mgc file

You must log in to answer this question.

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