1 '\" te
   2 .\" Copyright 1989 AT&T Copyright (c) 1992, X/Open Company Limited All Rights Reserved Portions Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved
   3 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
   4 .\" http://www.opengroup.org/bookstore/.
   5 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
   6 .\"  This notice shall appear on any product containing this material.
   7 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
   8 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
   9 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
  10 .TH FILE 1 "May 15, 2006"
  11 .SH NAME
  12 file \- determine file type
  13 .SH SYNOPSIS
  14 .LP
  15 .nf
  16 \fB/usr/bin/file\fR [\fB-dhs\fR] [\fB-m\fR \fImfile\fR] [\fB-M\fR \fIMfile\fR] [\fB-f\fR \fIffile\fR] \fIfile\fR...
  17 .fi
  18 
  19 .LP
  20 .nf
  21 \fB/usr/bin/file\fR [\fB-dhs\fR] [\fB-m\fR \fImfile\fR] [\fB-M\fR \fIMfile\fR] \fB-f\fR \fIffile\fR
  22 .fi
  23 
  24 .LP
  25 .nf
  26 \fB/usr/bin/file\fR \fB-i\fR [\fB-h\fR] [\fB-f\fR \fIffile\fR] \fIfile\fR...
  27 .fi
  28 
  29 .LP
  30 .nf
  31 \fB/usr/bin/file\fR \fB-i\fR [\fB-h\fR] \fB-f\fR \fIffile\fR
  32 .fi
  33 
  34 .LP
  35 .nf
  36 \fB/usr/bin/file\fR \fB-c\fR [\fB-d\fR] [\fB-m\fR \fImfile\fR] [\fB-M\fR \fIMfile\fR]
  37 .fi
  38 
  39 .LP
  40 .nf
  41 \fB/usr/xpg4/bin/file\fR [\fB-dhs\fR] [\fB-m\fR \fImfile\fR] [\fB-M\fR \fIMfile\fR] [\fB-f\fR \fIffile\fR] \fIfile\fR...
  42 .fi
  43 
  44 .LP
  45 .nf
  46 \fB/usr/xpg4/bin/file\fR [\fB-das\fR] [\fB-m\fR \fImfile\fR] [\fB-M\fR \fIMfile\fR] \fB-f\fR \fIffile\fR
  47 .fi
  48 
  49 .LP
  50 .nf
  51 \fB/usr/xpg4/bin/file\fR \fB-i\fR [\fB-h\fR] [\fB-f\fR \fIffile\fR] \fIfile\fR...
  52 .fi
  53 
  54 .LP
  55 .nf
  56 \fB/usr/xpg4/bin/file\fR \fB-i\fR [\fB-h\fR] \fB-f\fR \fIffile\fR
  57 .fi
  58 
  59 .LP
  60 .nf
  61 \fB/usr/xpg4/bin/file\fR \fB-c\fR [\fB-d\fR] [\fB-m\fR \fImfile\fR] [\fB-M\fR \fIMfile\fR]
  62 .fi
  63 
  64 .SH DESCRIPTION
  65 .sp
  66 .LP
  67 The \fBfile\fR utility performs a series of tests on each file supplied by
  68 \fIfile\fR and, optionally, on each file listed in \fIffile\fR in an attempt to
  69 classify it. If the file is not a regular file, its file type is identified.
  70 The file types directory, \fBFIFO\fR, block special, and character special are
  71 identified as such. If the file is a regular file and the file is zero-length,
  72 it is identified as an empty file.
  73 .sp
  74 .LP
  75 If \fIfile\fR appears to be a text file, \fBfile\fR examines the first 512
  76 bytes and tries to determine its programming language. If \fIfile\fR is a
  77 symbolic link, by default the link is followed and \fBfile\fR tests the file to
  78 which the symbolic link refers.
  79 .sp
  80 .LP
  81 If \fIfile\fR is a relocatable object, executable, or shared object, \fBfile\fR
  82 prints out information about the file's execution requirements. This
  83 information includes the machine class, byte-ordering, static/dynamic linkage,
  84 and any software or hardware capability requirements. If \fIfile\fR is a
  85 runtime linking configuration file, \fBfile\fR prints information about the
  86 target platform, including the machine class and byte-ordering.
  87 .sp
  88 .LP
  89 By default, \fBfile\fR will try to use the localized magic file
  90 \fB/usr/lib/locale/\fIlocale\fR/LC_MESSAGES/magic\fR, if it exists, to identify
  91 files that have a magic number. For example, in the Japanese locale, \fBfile\fR
  92 will try to use \fB/usr/lib/locale/ja/LC_MESSAGES/magic\fR. If a localized
  93 magic file does not exist, \fBfile\fR will utilize \fB/etc/magic\fR. A magic
  94 number is a numeric or string constant that indicates the file type. See
  95 \fBmagic\fR(4) for an explanation of the format of \fB/etc/magic\fR.
  96 .sp
  97 .LP
  98 If \fIfile\fR does not exist, cannot be read, or its file status could not be
  99 determined, it is not considered an error that affects the exit status. The
 100 output will indicate that the file was processed, but that its type could not
 101 be determined.
 102 .SH OPTIONS
 103 .sp
 104 .LP
 105 The following options are supported:
 106 .sp
 107 .ne 2
 108 .na
 109 \fB\fB-c\fR\fR
 110 .ad
 111 .RS 12n
 112 Checks the magic file for format errors. For reasons of efficiency, this
 113 validation is normally not carried out.
 114 .RE
 115 
 116 .sp
 117 .ne 2
 118 .na
 119 \fB\fB-d\fR\fR
 120 .ad
 121 .RS 12n
 122 Applies any position-sensitive and context-sensitive default system tests to
 123 the file.
 124 .RE
 125 
 126 .sp
 127 .ne 2
 128 .na
 129 \fB\fB-f\fR \fIffile\fR\fR
 130 .ad
 131 .RS 12n
 132 \fIffile\fR contains a list of the files to be examined.
 133 .RE
 134 
 135 .sp
 136 .ne 2
 137 .na
 138 \fB\fB-h\fR\fR
 139 .ad
 140 .RS 12n
 141 When a symbolic link is encountered, this option identifies the file as a
 142 symbolic link. If \fB-h\fR is not specified and \fIfile\fR is a symbolic link
 143 that refers to a non-existent file, the \fBfile\fR utility identifies the file
 144 as a symbolic link, as if \fB-h\fR had been specified.
 145 .RE
 146 
 147 .sp
 148 .ne 2
 149 .na
 150 \fB\fB-i\fR\fR
 151 .ad
 152 .RS 12n
 153 If a file is a regular file, this option does not attempt to classify the type
 154 of file further, but identifies the file as a "regular file".
 155 .RE
 156 
 157 .sp
 158 .ne 2
 159 .na
 160 \fB\fB-s\fR\fR
 161 .ad
 162 .RS 12n
 163 If a file is a block device or a character device, this option attempts to
 164 classify the contents of the device as if it were a regular file.
 165 .RE
 166 
 167 .sp
 168 .ne 2
 169 .na
 170 \fB\fB-m\fR \fImfile\fR\fR
 171 .ad
 172 .RS 12n
 173 .sp
 174 .ne 2
 175 .na
 176 \fB\fB/usr/bin/file\fR\fR
 177 .ad
 178 .RS 22n
 179 Uses \fImfile\fR as an alternate magic file, instead of \fB/etc/magic\fR.
 180 .RE
 181 
 182 .sp
 183 .ne 2
 184 .na
 185 \fB\fB/usr/xpg4/bin/file\fR\fR
 186 .ad
 187 .RS 22n
 188 Specifies the name of a file containing position-sensitive tests that are
 189 applied to a file in order to classify it (see \fBmagic\fR(4)). If the \fB-m\fR
 190 option is specified without specifying the \fB-d\fR option or the \fB-M\fR
 191 option, position-sensitive default system tests are applied after the
 192 position-sensitive tests specified by the \fB-m\fR option.
 193 .RE
 194 
 195 .RE
 196 
 197 .sp
 198 .ne 2
 199 .na
 200 \fB\fB-M\fR \fIMfile\fR\fR
 201 .ad
 202 .RS 12n
 203 Specifies the name of a file containing position-sensitive tests that are
 204 applied to a file in order to classify it (see \fBmagic\fR(4)). No
 205 position-sensitive default system tests nor context-sensitive default system
 206 tests are applied unless the \fB-d\fR option is also specified.
 207 .RE
 208 
 209 .sp
 210 .LP
 211 If the \fB-M\fR option is specified with the \fB-d\fR option, the \fB-m\fR
 212 option, or both, or if the \fB-m\fR option is specified with the \fB-d\fR
 213 option, the concatenation of the position-sensitive tests specified by these
 214 options is applied in the order specified by the appearance of these options.
 215 .SH OPERANDS
 216 .sp
 217 .LP
 218 The following operands are supported:
 219 .sp
 220 .ne 2
 221 .na
 222 \fB\fIfile\fR\fR
 223 .ad
 224 .RS 8n
 225 A path name of a file to be tested.
 226 .RE
 227 
 228 .SH USAGE
 229 .sp
 230 .LP
 231 See \fBlargefile\fR(5) for the description of the behavior of \fBfile\fR when
 232 encountering files greater than or equal to 2 Gbyte ( 2^31 bytes).
 233 .SH EXAMPLES
 234 .LP
 235 \fBExample 1 \fRDetermining if an Argument is a Binary Executable Files
 236 .sp
 237 .LP
 238 The following example determine if an argument is a binary executable file:
 239 
 240 .sp
 241 .in +2
 242 .nf
 243 file "$1" | grep \(miFq executable &&
 244           printf "%s is executable.\n" "$1"
 245 .fi
 246 .in -2
 247 .sp
 248 
 249 .SH ENVIRONMENT VARIABLES
 250 .sp
 251 .LP
 252 See \fBenviron\fR(5) for descriptions of the following environment variables
 253 that affect the execution of \fBfile\fR: \fBLANG\fR, \fBLC_ALL\fR,
 254 \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR.
 255 .SH EXIT STATUS
 256 .sp
 257 .LP
 258 The following exit values are returned:
 259 .sp
 260 .ne 2
 261 .na
 262 \fB\fB0\fR\fR
 263 .ad
 264 .RS 6n
 265 Successful completion.
 266 .RE
 267 
 268 .sp
 269 .ne 2
 270 .na
 271 \fB\fB>0\fR\fR
 272 .ad
 273 .RS 6n
 274 An error occurred.
 275 .RE
 276 
 277 .SH FILES
 278 .sp
 279 .ne 2
 280 .na
 281 \fB\fB/etc/magic\fR\fR
 282 .ad
 283 .RS 14n
 284 \fBfile\fR's magic number file
 285 .RE
 286 
 287 .SH ATTRIBUTES
 288 .sp
 289 .LP
 290 See \fBattributes\fR(5) for descriptions of the following attributes:
 291 .sp
 292 
 293 .sp
 294 .TS
 295 box;
 296 c | c
 297 l | l .
 298 ATTRIBUTE TYPE  ATTRIBUTE VALUE
 299 _
 300 CSI     Enabled
 301 _
 302 Interface Stability     Standard
 303 .TE
 304 
 305 .SH SEE ALSO
 306 .sp
 307 .LP
 308 \fBcrle\fR(1), \fBelfdump\fR(1), \fBls\fR(1), \fBmagic\fR(4),
 309 \fBattributes\fR(5), \fBenviron\fR(5), \fBlargefile\fR(5), \fBstandards\fR(5)