The Wayback Machine - https://web.archive.org/web/20180205000843/https://man.openbsd.org/file.1
file —
determine file typeThe
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 andfile is not running as root). The file format is described inmagic(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 input.
The options are as follows:
-
-
- -b,--brief
- Does not prepend filenames to output lines.
-
-
- -c
- Prints a summary of the parsed magic file; usually used for debugging.
-
-
- -h
- Causes symlinks not to be followed. This is the default.
-
-
- -i,--mime,--mime-type
- Outputs MIME type strings rather than the more traditional human-readable ones. Thus it may say “text/plain” rather than “ASCII text”.
-
-
- -L,--dereference
- Causes symlinks to be followed.
-
-
- -s
- Attempts to read block and character device files, not just regular files.
-
-
- -W
- Displays warnings when parsing the magic file or applying its tests. Usually used for debugging.
- /etc/magic
- default magic file
The
file utility exits 0 on success, and >0 if an error occurs.
magic(5)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
Ian Darwin.
There is a large number of contributors to the magic files; many are listed in the source files.