Name

file — stdin  stdout  - file  -- opt  --help  --version

Synopsis

file [options] files

The file command reports the type of a file:

file /etc/hosts /usr/bin/who letter.doc
/etc/hosts:    ASCII English text 
/usr/bin/who:  Mach-O universal binary ...
letter.doc:    CDF V2 Document, Little Endian, Os: MacOS ...

The reported file types are not always accurate; the file program has its roots in older operating systems that don’t track true file types the way the Macintosh does. The output is an educated guess based on file content and other factors.

Useful options

-b

Omit filenames (left column of output).

-I

Print MIME types for the file, such as “text/plain” or “audio/mpeg,” instead of the usual output.

-f name_file

Read filenames, one per line, from the given name_file, and report their types. Afterward, process filenames on the command line as usual.

-L

Follow symbolic links, reporting the type of the destination file instead of the link.

-z

If a file is compressed (see File Compression and Packaging), examine the uncompressed contents to decide the file type, instead of reporting “compressed data.”

Get Macintosh Terminal Pocket Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.