OpenBSD manual page server

Manual Page Search Parameters
FILE(1) General Commands Manual FILE(1)

filedetermine file type

file [-bchiLsW] file ...

The file utility tests each argument and attempts to determine its type. Three sets of tests are performed:

  1. Filesystem tests, for example if a file is empty, or a special file such as a socket or named pipe (FIFO).
  2. “Magic” tests for data in particular fixed formats. These are loaded from the /etc/magic file (or ~/.magic instead if it exists and file is not running as root). The file format is described in magic(5).
  3. 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 (contains only printing characters and is probably safe to read on an ASCII terminal), (the file contains a compiled executable program) or meaning anything else.

If file is a single dash (‘-’), file reads from the standard input.

The options are as follows:

, --brief
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.
, --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”.
, --dereference
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.

/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.

December 24, 2015 OpenBSD-current