[Go to CFHT Home Page] Man Pages
Back to Software Index  BORDER=0Manpage Top Level
    file(1) manual page Table of Contents

Name

file - determine file type

Synopsis

file [ -h ] [ -m mfile ] [ -f ffile ] file ...
file [ -h ] [ -m mfile ] -f ffile
file -c [ -m mfile ]

Availability

SUNWcsu

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 an executable a.out, file prints the version stamp, provided it is greater than 0. If file is a symbolic link, by default the link is followed and file tests the file to which the symbolic link refers.

By default, file uses /etc/magic to identify files that have a magic number. 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
Check the magic file for format errors. For reasons of efficiency, this validation is normally not carried out.
-h
Do not follow symbolic links.
-f ffile
ffile contains a list of the files to be examined.
-m mfile
Use mfile as an alternate magic file, instead of /etc/magic.

Operands

The following operands are supported:
file
A path name of a file to be tested.

Examples

Determine if an argument is a binary executable file:

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

Environment

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

Exit Status

The following exit values are returned:
  1. Successful completion.
    >0
    An error occurred.

    Files

    /etc/magic
    file’s magic number file

    See Also

    ls(1) , filehdr(4) , magic(4) , environ(5)

    Diagnostics

    If the -h option is specified and file is a symbolic link, file prints the error message:
    symbolic link to file


    Table of Contents