FILE(1P) POSIX Programmer's Manual FILE(1P) PROLOG This manual page is part of the POSIX Programmer's Man- ual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux. NAME file - determine file type SYNOPSIS file [-dh][-M file][-m file] file ... file -i [-h] file ... DESCRIPTION The file utility shall perform a series of tests in sequence on each specified file in an attempt to clas- sify it: 1. If file does not exist, cannot be read, or its file status could not be determined, the output shall indicate that the file was processed, but that its type could not be determined. 2. If the file is not a regular file, its file type shall be identified. The file types directory, FIFO, socket, block special, and character special shall be identified as such. Other implementation- defined file types may also be identified. If file is a symbolic link, by default the link shall be resolved and file shall test the type of file refer- enced by the symbolic link. (See the -h and -i options below.) 3. If the length of file is zero, it shall be identi- fied as an empty file. 4. The file utility shall examine an initial segment of file and shall make a guess at identifying its con- tents based on position-sensitive tests. (The answer is not guaranteed to be correct; see the -d, -M, and -m options below.) 5. The file utility shall examine file and make a guess at identifying its contents based on context-sensi- tive default system tests. (The answer is not guar- anteed to be correct.) 6. The file shall be identified as a data file. If file does not exist, cannot be read, or its file sta- tus could not be determined, the output shall indicate that the file was processed, but that its type could not be determined. If file is a symbolic link, by default the link shall be resolved and file shall test the type of file referenced by the symbolic link. OPTIONS The file utility shall conform to the Base Definitions volume of IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines, except that the order of the -m, -d, and -M options shall be significant. The following options shall be supported by the imple- mentation: -d Apply any position-sensitive default system tests and context-sensitive default system tests to the file. This is the default if no -M or -m option is specified. -h When a symbolic link is encountered, identify the file as a symbolic link. If -h is not specified and file is a symbolic link that refers to a nonexistent file, file shall identify the file as a symbolic link, as if -h had been specified. -i If a file is a regular file, do not attempt to classify the type of the file further, but iden- tify the file as specified in the STDOUT section. -M file Specify the name of a file containing position- sensitive tests that shall be applied to a file in order to classify it (see the EXTENDED DESCRIPTION). No position-sensitive default sys- tem tests nor context-sensitive default system tests shall be applied unless the -d option is also specified. -m file Specify the name of a file containing position- sensitive tests that shall be applied to a file in order to classify it (see the EXTENDED DESCRIPTION). If the -m option is specified without specifying the -d option or the -M option, position-sensitive default sys- tem tests shall be applied after the position-sensitive tests specified by the -m option. If the -M option is specified with the -d option, the -m option, or both, or the -m option is specified with the -d option, the con- catenation of the position-sensitive tests specified by these options shall be applied in the order specified by the appearance of these options. If a -M or -m file option-argument is -, the results are unspecified. OPERANDS The following operand shall be 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 shall affect the execution of file: LANG Provide a default value for the internationaliza- tion variables that are unset or null. (See the Base Definitions volume of IEEE Std 1003.1-2001, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale cate- gories.) LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte 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 mes- sages written to standard error and informative messages written to standard output. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES . ASYNCHRONOUS EVENTS Default. STDOUT In the POSIX locale, the following format shall be used to identify each operand, file specified: "%s: %s\n", , The values for are unspecified, except that in the POSIX locale, if file is identified as one of the types listed in the following table, shall con- tain (but is not limited to) the corresponding string, unless the file is identified by a position-sensitive test specified by a -M or -m option. Each space shown in the strings shall be exactly one . Table: File Utility Output Strings IEEE/The Open Group 2003 FILE(1P)