What does “magic tests” mean for the file command

file formatfile-commandterminology

I was reading about the file command and I came across something I don't quite understand:

file is designed to determine the kind of file being queried…. file
accomplishes this by performing three sets of tests on the file in
question:

  • filesystem tests,
  • magic tests,
  • language tests

What are magic tests?

Best Answer

That refers to the "magic bytes" which many file formats have at the beginning of a file which show what kind of file this is.

E.g. if a file starts with #! then it is considered a script.