How to create a custom magic file database

后端 未结 3 2064
有刺的猬
有刺的猬 2020-12-14 01:41

The unix file command uses a \"magic\" file database to determine which type of data a file contains, independently of the file\'s name or extension.

I

相关标签:
3条回答
  • 2020-12-14 02:21

    You can man magic for a description for how to create your own magic file. Then use file -C -m <your magic file> to compile it, and file -m <your magic file> to use it.

    0 讨论(0)
  • 2020-12-14 02:25

    I'm using the following magic file now for my unit tests:

    0       search/1/c      =<?php                  PHP script text
    !:mime  text/x-unittest
    

    With it, every php file (beginning with <?php) will get the MIME type text/x-unittest.


    Also see http://cweiske.de/tagebuch/custom-magic-db.htm

    0 讨论(0)
  • 2020-12-14 02:35

    In this article: https://linux.die.net/man/1/file (or man file)

    search for magic.mgc for explanation

    The information identifying these files is read from the compiled magic file /usr/share/file/magic.mgc, or /usr/share/file/magic if the compile file does not exist. In addition file will look in $HOME/.magic.mgc, or $HOME/.magic for magic entries.

    0 讨论(0)
提交回复
热议问题