[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Commands Reference, Volume 2


file Command

Purpose

Determines the file type.

Syntax

To Classify the File Type

file [ -m MagicFile] [ -f FileList] [File...]

To Check the Magic File for Format Errors

file -c [ -m MagicFile]

Description

The file command reads the files specified by the File parameter or the FileList variable, performs a series of tests on each file, and attempts to classify them by type. The command then writes the file types to standard output. The file can be regular file, directory, FIFO(named pipe), block special, character special, symbolic link or sockets type.

If a file appears to be in ASCII format, the file command examines the first 1024 bytes and determines the file type. If a file does not appear to be in ASCII format, the file command further attempts to distinguish a binary data file from a text file that contains extended characters.

If the File parameter specifies an executable or object module file and the version number is greater than 0, the file command displays the version stamp. The ld command explains the use of a.out files.

The file command uses the /etc/magic file to identify files that have some sort of a magic number; that is, any file containing a numeric or string constant that indicates type.

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

Flags


-c Checks the specified magic file (the /etc/magic file, by default) for format errors. This validation is not normally done. File typing is not done under this flag.
-f FileList Reads the specified file list. The file must list one file per line and must not contain leading or trailing spaces.
-m MagicFile Specifies the file name of the magic file (the /etc/magic file, by default).

Exit Status

This command returns the following exit values:

0 Successful completion.
>0 An error occurred.

Examples

  1. To display the type of information a file contains, enter:

    filemyfile
    

    This displays the file type of myfile (such as directory, data, ASCII text, C-program source, and archive).

  2. To display the type of each file named in a list of file names, enter:
    file -ffilenames
    This displays the type of each file named in the filenames list. Each file name must appear alone on a line.

Files


/usr/bin/file Contains the file command.
/etc/magic Contains the file type database.

Related Information

The find command, ld command.

Files Overview in AIX 5L Version 5.1 System User's Guide: Operating System and Devices describes files, file types, and how to name files.

Input and Output Redirection Overview in AIX 5L Version 5.1 System User's Guide: Operating System and Devices describes how the operating system processes input and output.

File and Directory Access Modes in AIX 5L Version 5.1 System User's Guide: Operating System and Devices introduces file ownership and permissions to access files and directories.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]