file(1)
Determine file type by examining contents and metadata.
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
| Flag | What it does |
|---|---|
-b, --brief | Only print the file type, omit the filename |
-i, --mime-type | Print MIME type instead of human-readable description |
-I, --mime | Print MIME type and charset encoding |
-L, --dereference | Follow symbolic links and check the target file |
-h, --no-dereference | Don't follow symbolic links (default behavior) |
-s, --special-files | Read block and character device files (may hang) |
-z, --uncompress | Try to look inside gzip, bzip2, and compress compressed files |
-e, --exclude TESTNAME | Exclude a specific test (e.g., compress, elf, tokens) |
-k, --keep-going | Don't stop after first match; continue testing |
-f FILE | Read filenames from FILE, one per line (use - for stdin) |
Examples
Identify the type of myfile.txt regardless of extension
file myfile.txtShow only the type without the filename prefix
file -b image.jpgDisplay MIME type (application/pdf) instead of description
file -i document.pdfExamine contents of compressed tar archive without extracting
file -z archive.tar.gzCheck the actual file that symlink points to, not the link itself
file -L symlinkIdentify all files in current directory in one pass
file *Identify each file listed in filelist.txt
file -f filelist.txtDisplay filesystem type of a partition (may require root)
file /dev/sda1