FILE(1)FILE(1)NAMEfile - determine file type
/usr/bin/file [-bdh] [-m mfile] [-M Mfile] [-f ffile] file...
/usr/bin/file [-bdh] [-m mfile] [-M Mfile] -f ffile
/usr/bin/file -i [-bh] [-f ffile] file...
/usr/bin/file -i [-bh] -f ffile
/usr/bin/file -c [-d] [-m mfile] [-M Mfile]
/usr/xpg4/bin/file [-bdh] [-m mfile] [-M Mfile] [-f ffile] file...
/usr/xpg4/bin/file [-bdh] [-m mfile] [-M Mfile] -f ffile
/usr/xpg4/bin/file -i [-bh] [-f ffile] file...
/usr/xpg4/bin/file -i [-bh] -f ffile
/usr/xpg4/bin/file -c [-d] [-m mfile] [-M Mfile]
The file utility performs a series of tests on each file supplied by
file and, optionally, on each file listed in ffile in an attempt to
classify it. If the file is not a regular file, its file type is iden‐
tified. The file types directory, FIFO, block special, and character
special are identified as such. If the file is a regular file and the
file is zero-length, it is identified as an empty file.
If file appears to be a text file, file examines the first 512 bytes
and tries to determine its programming language. If file is a symbolic
link, by default the link is followed and file tests the file to which
the symbolic link refers.
If file is a relocatable object, executable, or shared object, file
prints out information about the file's execution requirements. This
information includes the machine class, byte-ordering, static/dynamic
linkage, and any software or hardware capability requirements. If file
is a runtime linking configuration file, file prints information about
the target platform, including the machine class and byte-ordering.
By default, file will try to use the localized magic file
/usr/lib/locale/locale/LC_MESSAGES/magic, if it exists, to identify
files that have a magic number. For example, in the Japanese locale,
file will try to use /usr/lib/locale/ja/LC_MESSAGES/magic. If a local‐
ized magic file does not exist, file will utilize /etc/magic. A magic
number is a numeric or string constant that indicates the file type.
See magic(4) for an explanation of the format of /etc/magic.
If file does not exist, cannot be read, or its file status could not be
determined, it is not considered an error that affects the exit status.
The output will indicate that the file was processed, but that its type
could not be determined.
The following options are supported:
Be brief, do not print leading filename.
Checks the magic file for format errors. For reasons of
efficiency, this validation is normally not carried out.
Applies any position-sensitive and context-sensitive
default system tests to the file.
ffile contains a list of the files to be examined.
When a symbolic link is encountered, this option identifies
the file as a symbolic link. If -h is not specified and
file is a symbolic link that refers to a non-existent file,
the file utility identifies the file as a symbolic link, as
if -h had been specified.
If a file is a regular file, this option does not attempt
to classify the type of file further, but identifies the
file as a "regular file".
Uses mfile as an alternate magic
file, instead of /etc/magic.
Specifies the name of a file contain‐
ing position-sensitive tests that are
applied to a file in order to clas‐
sify it (see magic(4)). If the -m
option is specified without specify‐
ing the -d option or the -M option,
position-sensitive default system
tests are applied after the position-
sensitive tests specified by the -m
Specifies the name of a file containing position-sensitive
tests that are applied to a file in order to classify it
(see magic(4)). No position-sensitive default system tests
nor context-sensitive default system tests are applied
unless the -d option is also specified.
If the -M option is specified with the -d option, the -m option, or
both, or if the -m option is specified with the -d option, the concate‐
nation of the position-sensitive tests specified by these options is
applied in the order specified by the appearance of these options.
The following operands are supported:
A path name of a file to be tested.
See largefile(5) for the description of the behavior of file when
encountering files greater than or equal to 2 Gbyte ( 2^31 bytes).
Example 1 Determining if an Argument is a Binary Executable Files
The following example determine if an argument is a binary executable
file "$1" | grep −Fq executable &&
printf "%s is executable.\n" "$1"
See environ(5) for descriptions of the following environment variables
that affect the execution of file: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES,
The following exit values are returned:
An error occurred.
file's magic number fileATTRIBUTES
See attributes(5) for descriptions of the following attributes:
│ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
│CSI │ Enabled │
│Interface Stability │ Standard │
SEE ALSOcrle(1), elfdump(1), ls(1), magic(4), attributes(5), environ(5), large‐
Apr 11, 2014 FILE(1)