File command

The  command is a file format identification utility that has been a part of Unix distributions for many years.

The Debian manpage gives an overview of its functionality

The program source includes a database of heuristics for determining file types, which includes a variety of 'magic numbers' which characterise files. This database is not portable, but is potentially adaptable.

Links

 * File Command web site
 * Source code
 * FreeBSD port tree (referring to the porting of the original distribution into FreeBSD)