xref: /titanic_41/usr/src/man/man1/file.1 (revision 1babaf948dd28d81d79cf3ec089d6edc111ed4a8)
te
Copyright 1989 AT&T Copyright (c) 1992, X/Open Company Limited All Rights Reserved Portions Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved
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
http://www.opengroup.org/bookstore/.
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.
This notice shall appear on any product containing this material.
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.
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.
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]
FILE 1 "May 15, 2006"
NAME
file - determine file type
SYNOPSIS

/usr/bin/file [-dh] [-m mfile] [-M Mfile] [-f ffile] file...

/usr/bin/file [-dh] [-m mfile] [-M Mfile] -f ffile

/usr/bin/file -i [-h] [-f ffile] file...

/usr/bin/file -i [-h] -f ffile

/usr/bin/file -c [-d] [-m mfile] [-M Mfile]

/usr/xpg4/bin/file [-dh] [-m mfile] [-M Mfile] [-f ffile] file...

/usr/xpg4/bin/file [-dh] [-m mfile] [-M Mfile] -f ffile

/usr/xpg4/bin/file -i [-h] [-f ffile] file...

/usr/xpg4/bin/file -i [-h] -f ffile

/usr/xpg4/bin/file -c [-d] [-m mfile] [-M Mfile]
DESCRIPTION

The file utility performs a series of tests on each file supplied by file and, optionally, on each file listed in ffile 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. If the file is a regular file and the file is zero-length, it is identified as an empty file.

If file appears to be a text file, file examines the first 512 bytes and tries to determine its programming language. If file is a symbolic link, by default the link is followed and file tests the file to which the symbolic link refers.

If file is a relocatable object, executable, or shared object, file prints out information about the file's execution requirements. This information includes the machine class, byte-ordering, static/dynamic linkage, and any software or hardware capability requirements. If file is a runtime linking configuration file, file prints information about the target platform, including the machine class and byte-ordering.

By default, file will try to use the localized magic file /usr/lib/locale/locale/LC_MESSAGES/magic, if it exists, to identify files that have a magic number. For example, in the Japanese locale, file will try to use /usr/lib/locale/ja/LC_MESSAGES/magic. If a localized magic file does not exist, file will utilize /etc/magic. A magic number is a numeric or string constant that indicates the file type. See magic(4) for an explanation of the format of /etc/magic.

If file does not exist, cannot be read, or its file status could not be determined, it is not considered an error that affects the exit status. The output will indicate that the file was processed, but that its type could not be determined.

OPTIONS

The following options are supported: -c

Checks the magic file for format errors. For reasons of efficiency, this validation is normally not carried out.

-d

Applies any position-sensitive and context-sensitive default system tests to the file.

-f ffile

ffile contains a list of the files to be examined.

-h

When a symbolic link is encountered, this option identifies the file as a symbolic link. If -h is not specified and file is a symbolic link that refers to a non-existent file, the file utility identifies the file as a symbolic link, as if -h had been specified.

-i

If a file is a regular file, this option does not attempt to classify the type of file further, but identifies the file as a "regular file".

-m mfile

/usr/bin/file

Uses mfile as an alternate magic file, instead of /etc/magic.

/usr/xpg4/bin/file

Specifies the name of a file containing position-sensitive tests that are applied to a file in order to classify it (see magic(4)). If the -m option is specified without specifying the -d option or the -M option, position-sensitive default system tests are applied after the position-sensitive tests specified by the -m option.

-M Mfile

Specifies the name of a file containing position-sensitive tests that are applied to a file in order to classify it (see magic(4)). No position-sensitive default system tests nor context-sensitive default system tests are applied unless the -d option is also specified.

If the -M option is specified with the -d option, the -m option, or both, or if the -m option is specified with the -d option, the concatenation of the position-sensitive tests specified by these options is applied in the order specified by the appearance of these options.

OPERANDS

The following operands are supported: file

A path name of a file to be tested.

USAGE

See largefile(5) for the description of the behavior of file when encountering files greater than or equal to 2 Gbyte ( 2^31 bytes).

EXAMPLES

Example 1 Determining if an Argument is a Binary Executable Files

The following example determine if an argument is a binary executable file:

file "$1" | grep -Fq executable &&
 printf "%s is executable.\n" "$1"
ENVIRONMENT VARIABLES

See environ(5) for descriptions of the following environment variables that affect the execution of file: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES, and NLSPATH.

EXIT STATUS

The following exit values are returned: 0

Successful completion.

>0

An error occurred.

FILES
/etc/magic

file's magic number file

ATTRIBUTES

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPE ATTRIBUTE VALUE
CSI Enabled
Interface Stability Standard
SEE ALSO

crle(1), elfdump(1), ls(1), magic(4), attributes(5), environ(5), largefile(5), standards(5)