file(1) file(1)
NAME
file - check type of file
SYNOPSIS
file [-h] [-m magicfile] [-f ffile] [argfile ...] Format 1
file -c [-m magicfile] Format 2
DESCRIPTION
The file command takes a list of one or more files and classifies each
file on the basis of its contents. The types distinguished by file
include directories, special files, FIFO files, archive libraries, C
source programs, executable programs, shell scripts, and normal text
files.
Caution:
file looks up the magic number in the magic file to identify the
target file. If it fails to identify the file by this method, it
tries various plausibility checks. Consequently the results are
not always reliable.
OPTIONS
Format 1: Classify a file
file [-h] [-m magicfile] [-f ffile] [argfile ...]
-h (hidden) If argfile is a symbolic link, the link will not be fol-
lowed and the following error message will be printed:
file1: symbolic link to file2
-m magicfile
(magic) Causes file to use magicfile instead of the system file
/etc/magic to identify the magic numbers of the files being clas-
sified.
-f ffile
file interprets the ffile argument as the name of a file which
contains the names of all files to be examined. If this option is
omitted, you must name at least one file to be classified.
argfile
Name of the file to be classified by the file command. If argfile
is a symbolic link, file will follow the link and test the origi-
nal file referenced by the symbolic link. You can name any number
of files. If the -f option is omitted, you must name at least
one.
Page 1 Reliant UNIX 5.44 Printed 11/98
file(1) file(1)
Output
file writes its file classification to standard output. The following
table lists the most important file types that file classifies:
______________________________________________________________________
| Output | Meaning |
|________________________|____________________________________________|
| ASCII cpio archive | Archive generated by cpio, option -c |
|________________________|____________________________________________|
| ascii text | Text file |
|________________________|____________________________________________|
| assembler program text | Assembler source program |
|________________________|____________________________________________|
| block special | Block special file |
|________________________|____________________________________________|
| c program text | C source program |
|________________________|____________________________________________|
| character special | Character special file |
|________________________|____________________________________________|
| commands text | Shell script |
|________________________|____________________________________________|
| compressed data | Compressed file [see compress(1)] |
|________________________|____________________________________________|
| cpio archive | Archive generated by cpio |
|________________________|____________________________________________|
| current ar archive | Archive library [see ar(1)] |
|________________________|____________________________________________|
| data | Data file |
|________________________|____________________________________________|
| directory | Directory |
|________________________|____________________________________________|
| ELF 32-bit | ELF object file; possible types: |
| core file | Core dump (file) |
| dynamic lib | Dynamic library |
| executable | Executable file |
| relocatable | Relocatable file |
| unknown | Type unknown |
|________________________|____________________________________________|
| empty | Empty file |
|________________________|____________________________________________|
| English text | Text file with English text |
|________________________|____________________________________________|
| fifo | FIFO file |
|________________________|____________________________________________|
| fortran program text | FORTRAN source program |
|________________________|____________________________________________|
| [nt]roff, tbl, or eqn | File in nroff, troff, tbl or eqn format |
| input text | input text |
|________________________|____________________________________________|
Page 2 Reliant UNIX 5.44 Printed 11/98
file(1) file(1)
______________________________________________________________________
| Output | Meaning |
|________________________|____________________________________________|
| packed data | compressed file [see pack(1)] |
|________________________|____________________________________________|
| sccs | SCCS file |
|________________________|____________________________________________|
| tar archive | Library, generated with tar |
|________________________|____________________________________________|
| troff output | troff output file |
|________________________|____________________________________________|
Classification of executable programs goes into further detail. For
example, if the symbol table has not been removed, file displays the
message: not stripped [see strip(1)].
Mode of operation
file performs a series of tests on each input file and attempts to
classify it on the basis of its contents. If it appears to be a text
file, file examines an initial segment (the first 512 bytes) and tries
to guess the language it was created in. The accuracy of the guess
cannot be guaranteed, however.
If the input file is an executable program, it is identified as such,
and further information is provided with respect to its contents. To
do this, file searches the file for "magic numbers", i.e. for numeric
constants or string constants that give an indication of the type of
file. The file /etc/magic contains an explanation of these magic numbers.
Format 2: Check the magic file
file -c [-m magicfile]
-c (check) The magic file, by default the system file /etc/magic, is
checked for format errors. However, if the -m option is speci-
fied, the magic file magicfile is checked instead.
-m magicfile
(magic file) Causes file to check the alternate magic file
magicfile for format errors.
LOCALE
The LCMESSAGES environment variable governs the language in which
message texts are displayed. If LCMESSAGES is undefined or is defined
as the null string, it defaults to the value of LANG. If LANG is like-
wise undefined or null, the system acts as if it were not internation-
alized.
The LCALL environment variable governs the entire locale. LCALL
takes precedence over all the other environment variables which affect
internationalization.
Page 3 Reliant UNIX 5.44 Printed 11/98
file(1) file(1)
EXAMPLES
The file list contains the following file names:
dir
letter
lib.a
prog.c
prog.s
prog.o
prog
The following command line will yield information on the contents of
each classified file type:
$ file -f list
dir: directory
letter: ascii text
lib.a: current ar archive
prog.c: c program text
prog.s: assembler program text
prog.o: ELF 32-bit LSB relocatable 80386 Version 1
prog: ELF 32-bit LSB executable 80386 Version 1
Thus dir is a directory, and letter contains normal ASCII text. lib.a
is an archive library; prog.c contains a C program. prog.s probably
contains an Assembler source program (no guarantee!). prog.o is an
object module, prog an executable program, both in ELF format (Execut-
able and Linking Format).
The same output could also have been obtained with a command line
reading:
$ file dir letter lib.a prog.c prog.s prog.o prog
FILES
/etc/magic
File containing a key to the magic numbers
SEE ALSO
cc(1), ls(1), strip(1), filehdr(4).
Page 4 Reliant UNIX 5.44 Printed 11/98