LinuxCommandLibrary

file

content-based file type identification

TLDR

Determine file type

$ file [filename]
copy
Check multiple files
$ file [file1] [file2] [file3]
copy
Show MIME type
$ file --mime-type [filename]
copy
Follow symlinks
$ file -L [symlink]
copy
Read from stdin
$ cat [file] | file -
copy

SYNOPSIS

file [options] files...

DESCRIPTION

file determines file types by examining content rather than extensions. It uses magic number patterns and heuristics from a database to identify formats.
The tool recognizes thousands of file types including executables, archives, documents, images, and text encodings. It examines file headers and content patterns rather than trusting filename extensions.
file is essential for identifying unknown files and verifying file types in scripts.

PARAMETERS

FILES

Files to identify.
-b, --brief
Omit filename from output.
-i, --mime
Output MIME type and encoding.
--mime-type
Output MIME type only.
-L, --dereference
Follow symlinks.
-z, --uncompress
Look inside compressed files.
-f FILE
Read filenames from file.
--help
Display help information.

CAVEATS

May misidentify corrupted or unusual files. Custom formats may not be recognized. Magic database completeness varies.

HISTORY

file dates back to Unix Version 6 (1975). The magic file database approach was developed to identify the many file formats accumulating on Unix systems.

SEE ALSO

stat(1), hexdump(1), identify(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community