📄 file.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>file</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_001_014_719"> </a>NAME</h4><blockquote>file - determine file type</blockquote><h4><a name = "tag_001_014_720"> </a>SYNOPSIS</h4><blockquote><pre><code></pre><i>file</i><i>file ...</i></code></blockquote><h4><a name = "tag_001_014_721"> </a>DESCRIPTION</h4><blockquote>The<i>file</i>utilityperforms a series of tests on each specified<i>file</i>in an attempt to classify it:<ol><p><li>If the file is not a regular file, its file type is identified.The file types directory, FIFO, block special and character specialare identified as such.Other implementation-dependent file types may also be identified.<p><li>If the file is a regular file, and:<ol type = a><p><li>The file is zero-length, it is identified as an empty file.<p><li>The file is not zero-length,<i>file</i>will examine an initial segment of the fileand make a guess at identifying itscontents or whether it is an executable binary file.(The answer is not guaranteed to be correct.)<p></ol><p></ol><p>If<i>file</i>does not exist, cannot be read,or its file status could not be determined, the output will indicatethat the file was processed,but that its type could not be determined.</blockquote><h4><a name = "tag_001_014_722"> </a>OPTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_001_014_723"> </a>OPERANDS</h4><blockquote>The following operand is supported:<dl compact><dt><i>file</i><dd>A pathname of a file to be tested.</dl></blockquote><h4><a name = "tag_001_014_724"> </a>STDIN</h4><blockquote>Not used.</blockquote><h4><a name = "tag_001_014_725"> </a>INPUT FILES</h4><blockquote>The<i>file</i>can be any file type.</blockquote><h4><a name = "tag_001_014_726"> </a>ENVIRONMENT VARIABLES</h4><blockquote>The following environment variables affect the execution of<i>file</i>:<dl compact><dt><i>LANG</i><dd>Provide a default value for the internationalisation variablesthat are unset or null.If<i>LANG</i>is unset or null, the corresponding value from theimplementation-dependent default locale will be used.If any of the internationalisation variables contains an invalid setting, theutility will behave as if none of the variables had been defined.<dt><i>LC_ALL</i><dd>If set to a non-empty string value,override the values of all the other internationalisation variables.<dt><i>LC_CTYPE</i><dd>Determine thelocale for the interpretation of sequences of bytes of text data ascharacters (for example, single- as opposed to multi-byte charactersin arguments and input files).<dt><i>LC_MESSAGES</i><dd>Determine the locale that should be used to affectthe format and contents of diagnosticmessages written to standard errorand informative messages written to standard output.<dt><i>NLSPATH</i><dd>Determine the location of message cataloguesfor the processing of<i>LC_MESSAGES .</i></dl></blockquote><h4><a name = "tag_001_014_727"> </a>ASYNCHRONOUS EVENTS</h4><blockquote>Default.</blockquote><h4><a name = "tag_001_014_728"> </a>STDOUT</h4><blockquote>In the POSIX locale, the following format is used to identifyeach operand,<i>file</i>specified:<p><code><tt>"%s: %s\n"</tt>, <<i>file</i>>,<<i>type</i>></code><p>The values for<<i>type</i>>are unspecified, except that in the POSIX locale,if<i>file</i>is identified as one of the types listed in the following table,<<i>type</i>>will contain (but is not limited to) the corresponding string.Each space shown in the strings is exactly onespacecharacter.<pre><table bordercolor=#000000 border=1 align=center><tr valign=top><th align=center><b>If <i>file</i> is a:</b><th align=center><b><<i>type</i>> Contains the String:</b><tr valign=top><td align=left>directory<td align=left>directory<tr valign=top><td align=left>FIFO<td align=left>fifo<tr valign=top><td align=left>block special<td align=left>block special<tr valign=top><td align=left>character special<td align=left>character special<tr valign=top><td align=left>executable binary<td align=left>executable<tr valign=top><td align=left>empty regular file<td align=left>empty<tr valign=top><td align=left><i>ar</i> archive library (see <i>ar</i>)<td align=left>archive<tr valign=top><td align=left>extended <i>cpio</i> format (see <i>pax</i>)<td align=left>cpio archive<tr valign=top><td align=left>extended <i>tar</i> format (see <i>ustar</i> - see <i>pax</i>)<td align=left>tar archive<tr valign=top><td align=left>shell script<td align=left>commands text<tr valign=top><td align=left>C-language source<td align=left>c program text<tr valign=top><td align=left>FORTRAN source<td align=left>fortran program text</table></pre><h6 align=center><xref table="File Utility Output Strings"><a name="tagt_4"> </a></xref>Table: File Utility Output Strings</h6><p>If the file named by the<i>file</i>operand does not exist, cannot be read or the status of the filecannot be determined, the string<b>cannot open</b>will be included as part of the<<i>type</i>>field, but this is not considered an errorthat affects the exit status.</blockquote><h4><a name = "tag_001_014_729"> </a>STDERR</h4><blockquote>Used only for diagnostic messages.</blockquote><h4><a name = "tag_001_014_730"> </a>OUTPUT FILES</h4><blockquote>None.</blockquote><h4><a name = "tag_001_014_731"> </a>EXTENDED DESCRIPTION</h4><blockquote>None.</blockquote><h4><a name = "tag_001_014_732"> </a>EXIT STATUS</h4><blockquote>The following exit values are returned:<dl compact><dt>0<dd>Successful completion.<dt>>0<dd>An error occurred.</dl></blockquote><h4><a name = "tag_001_014_733"> </a>CONSEQUENCES OF ERRORS</h4><blockquote>Default.<br></blockquote><h4><a name = "tag_001_014_734"> </a>APPLICATION USAGE</h4><blockquote>The<i>file</i>utility can only be required to guess at many ofthe file types because only exhaustive testingcan determine some types with certitude.For example, binary data on some systems mightmatch the initial segment of an executable or a<i><a href="tar.html">tar</a></i>archive.<p>Note that the table indicates thatthe output contains the stated string.Systems may add text before or after the string.For executables, as an example, the machinearchitecture and various facts about howthe file was link-edited may be included.</blockquote><h4><a name = "tag_001_014_735"> </a>EXAMPLES</h4><blockquote>Determine if an argument is a binary executable file:<pre><code>file "$1" | grep -Fq executable && printf "%s is executable.\n" "$1"</code></pre></blockquote><h4><a name = "tag_001_014_736"> </a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_001_014_737"> </a>SEE ALSO</h4><blockquote><i><a href="ls.html">ls</a></i>.</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -