NAME
file — determine
file type
SYNOPSIS
file |
file ... |
DESCRIPTION
The file utility performs a series of
tests on each specified file in an attempt to
classify it:
- If the file is not a regular file, its file type is identified. The file types directory, FIFO, block special and character special are identified as such. Other implementation-dependent file types may also be identified.
- If the file is a regular file, and:
- The file is zero-length, it is identified as an empty file.
The file is not zero-length,
filewill examine an initial segment of the file and make a guess at identifying its contents or whether it is an executable binary file. (The answer is not guaranteed to be correct.)
If file does not exist, cannot be read, or
its file status could not be determined, the output will indicate that the
file was processed, but that its type could not be determined.
OPTIONS
None.
OPERANDS
The following operand is supported:
- file
- A pathname of a file to be tested.
STDIN
Not used.
INPUT FILES
The file can be any file type.
ENVIRONMENT VARIABLES
The following environment variables affect the execution of
file :
LANG- Provide a default value for the internationalisation variables that are
unset or null. If
LANGis unset or null, the corresponding value from the implementation-dependent default locale will be used. If any of the internationalisation variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL- If set to a non-empty string value, override the values of all the other internationalisation variables.
LC_CTYPE- Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files).
LC_MESSAGES- Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output.
NLSPATH- Determine the location of message catalogues for the processing of LC_MESSAGES .
ASYNCHRONOUS EVENTS
Default.
STDOUT
In the POSIX locale, the following format is used to identify each
operand, file specified:
"%s: %s\n", <file>,
<type>
The values for < type > are unspecified,
except that in the POSIX locale, if file is
identified as one of the types listed in the following table, <
type > will contain (but is not limited to) the
corresponding string. Each space shown in the strings is exactly one space
character.
| If file is a: | <type> Contains the String: |
| directory | directory |
| FIFO | fifo |
| block special | block special |
| character special | character special |
| executable binary | executable |
| empty regular file | empty |
| ar archive library (see ar) | archive |
| extended cpio format (see pax) | cpio archive |
| extended tar format (see ustar - see pax) | tar archive |
| shell script | commands text |
| C-language source | c program text |
| FORTRAN source | fortran program text |
Table: File Utility Output Strings
If the file named by the file operand does
not exist, cannot be read or the status of the file cannot be determined,
the string
cannot
open will be included as part of the < type
> field, but this is not considered an error that affects the exit
status.
STDERR
Used only for diagnostic messages.
OUTPUT FILES
None.
EXTENDED DESCRIPTION
None.
EXIT STATUS
The following exit values are returned:
CONSEQUENCES OF ERRORS
Default.
APPLICATION USAGE
The file utility can only be required to
guess at many of the file types because only exhaustive testing can
determine some types with certitude. For example, binary data on some
systems might match the initial segment of an executable or a
tar(1) archive.
Note that the table indicates that the output contains the stated string. Systems may add text before or after the string. For executables, as an example, the machine architecture and various facts about how the file was link-edited may be included.
EXAMPLES
Determine if an argument is a binary executable file:
file "$1" | grep -Fq executable &&
printf "%s is executable.\n" "$1"
FUTURE DIRECTIONS
None.
SEE ALSO
ls(1) .