Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a custom magic file database

Tags:

file

unix

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 need to craft my custom magic database for testing purposes, but I fail to find how to create one.

like image 669
cweiske Avatar asked Sep 06 '25 03:09

cweiske


2 Answers

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.

like image 158
Jon Lin Avatar answered Sep 09 '25 00:09

Jon Lin


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.

like image 40
Marek Sebera Avatar answered Sep 09 '25 02:09

Marek Sebera