$linuxjunkies
>

file(1)

Determine file type by examining contents and metadata.

UbuntuDebianFedoraArch

Synopsis

file [OPTION]... FILE...

Description

The file command identifies the type of a file by reading its magic bytes (file signature), file system metadata, and other characteristics. It doesn't rely on file extensions, making it useful for identifying files with incorrect or missing extensions.

The command consults a database of file signatures to classify files as text, binary, archives, images, executables, and many other types. It can also detect encoding, permissions, and other file properties.

Common options

FlagWhat it does
-b, --briefOnly print the file type, omit the filename
-i, --mime-typePrint MIME type instead of human-readable description
-I, --mimePrint MIME type and charset encoding
-L, --dereferenceFollow symbolic links and check the target file
-h, --no-dereferenceDon't follow symbolic links (default behavior)
-s, --special-filesRead block and character device files (may hang)
-z, --uncompressTry to look inside gzip, bzip2, and compress compressed files
-e, --exclude TESTNAMEExclude a specific test (e.g., compress, elf, tokens)
-k, --keep-goingDon't stop after first match; continue testing
-f FILERead filenames from FILE, one per line (use - for stdin)

Examples

Identify the type of myfile.txt regardless of extension

file myfile.txt

Show only the type without the filename prefix

file -b image.jpg

Display MIME type (application/pdf) instead of description

file -i document.pdf

Examine contents of compressed tar archive without extracting

file -z archive.tar.gz

Check the actual file that symlink points to, not the link itself

file -L symlink

Identify all files in current directory in one pass

file *

Identify each file listed in filelist.txt

file -f filelist.txt

Display filesystem type of a partition (may require root)

file /dev/sda1

Related commands