file Identify what type a file is
Looks at the contents of a file, not its name, and tells you what kind of data it holds. Use it when a file has no extension, the wrong extension, or you want to know whether it is text, an image, an archive or a program.
Synopsis
file [OPTION]... FILE...
file -f NAMEFILE
Common options
| Option or form | What it does |
|---|---|
-b, --brief | Brief: print the type only, without the file name in front |
--mime-type | Print only the MIME type, such as text/plain or image/jpeg |
-I, --mime | On macOS, print the MIME type and character set. On GNU/Linux the same job is done by -i (see notes) |
-L, --dereference | Follow symbolic links and report on what they point to |
-h, --no-dereference | Do not follow symbolic links, so a link is reported as a link |
-f, --files-from | Read the list of files to check from a file, one name per line |
-k, --keep-going | Keep looking after the first match and show every match |
-z, --uncompress | Look inside compressed files and describe the content |
Examples
file notes.txt
notes.txt: ASCII text
file notes.txt data.csv script.sh photos/a.jpg
file docs/*
file -b notes.txt
ASCII text
file --mime-type notes.txt
notes.txt: text/plain
file ~/Downloads/mystery-download
Notes
- file guesses from the first part of the content using a database of patterns. The answer is usually right but it is a guess, so do not use it as a security check on untrusted uploads.
- The MIME flag differs by platform. On macOS, -I (capital i) prints the MIME type and -i means something else. On GNU/Linux, -i prints the MIME type. --mime-type works on both.
- Symlink behaviour differs. GNU file reports a symlink as a link unless you pass -L. macOS file followed the link in our check. Pass -L or -h to be explicit.
- Wording of the results varies between systems and versions. Match on key words such as text, executable or JPEG, not on the exact sentence.
- An empty file is reported as empty, and a file with no recognisable pattern as data.
See also
Last reviewed 2026-10-07.