determine file type
file utility tests each argument and
attempts to determine its type. Three sets of tests are performed:
- Filesystem tests, for example if a file is empty, or a special file such as a socket or named pipe (FIFO).
- “Magic” tests for data in particular fixed formats. These
are loaded from the /etc/magic file (or
~/.magic instead if it exists and
fileis not running as root). The file format is described in magic(5).
- Tests for text files such as plain ASCII or C programming language files.
The first test which succeeds causes the file type to be printed. The type will often contain one of the words text (contains only printing characters and is probably safe to read on an ASCII terminal), executable (the file contains a compiled executable program) or data meaning anything else.
If file is a single dash
file reads from the standard
The options are as follows:
- Does not prepend filenames to output lines.
- Prints a summary of the parsed magic file; usually used for debugging.
- Causes symlinks not to be followed. This is the default.
- Outputs MIME type strings rather than the more traditional human-readable ones. Thus it may say “text/plain” rather than “ASCII text”.
- Causes symlinks to be followed.
- Attempts to read block and character device files, not just regular files.
- Displays warnings when parsing the magic file or applying its tests. Usually used for debugging.
- default magic file
file utility exits 0 on
success, and >0 if an error occurs.
file commands have appeared in many
previous versions of UNIX. This version was written
by Nicholas Marriott for OpenBSD
5.8 to replace the previous version originally written by
There is a large number of contributors to the magic files; many are listed in the source files.