Specification
The Single Unix Specification (SUS) specifies that a series of tests are performed on the file specified on the command line:
- if the file cannot be read, its status undetermined, or its type undetermined, file will indicate that the file was processed and its type was undetermined.
- file must be able to determine the types directory, FIFO, socket, block special file, and character special file
- zero-length files are identified as such
- an initial part of file is considered and file is to use position-sensitive tests
- the entire file is considered and file is to use context-sensitive tests
- the file is identified as a data file
file's position-sensitive tests are normally implemented by matching various locations within the file against a textual database of magic numbers (see the Usage section). This differs from other simpler methods such as file extensions and schemes like MIME.
In most implementations, the file command uses a database to drive the probing of the lead bytes. That database is implemented in a file called magic, whose location is usually in /etc/magic, /usr/share/file/magic or a similar location.
Read more about this topic: File (command)