We can create magic files with file -C -m filename. Also there is the /usr/share/file/magic folder with a list of magic files on my OS X machine.

But what is this? Would somebody explain, why should we have magic files? How should we create a magic file?

I read the man pages (man file and man magic), but it is still not clear.

closed as unclear what you're asking by Michael Homer, Stephen Rauch, G-Man, muru, αғsнιη Sep 20 '17 at 4:51

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Look at the file(1) man page and it may become clear. – Deathgrip Sep 19 '17 at 22:38
  • 2
    What parts of the manpages did you not understand? – muru Sep 20 '17 at 4:07

In Unix a file is just a sequence of bytes, however some files have more structure. The file command can look at the sequence of bytes and tell you things.for example if the first 4bytes are \177 E L F then it will tell you it is an elf file. It will then look at more bytes and tell you if it is a core file, an executable or an object file. If the bytes 6 thru 9 are JFIF then it is a picture file and again the program can read more and tell you about it.

A lot of this is driven by data tables rather than being compiled into the program. These data tables are what is in the magic files.

So the reason why you have magic files is to allow you to say file * and get the program to tell you what you have in the current directory.

Not the answer you're looking for? Browse other questions tagged or ask your own question.