file command in Linux: identify a file's type
Updated July 3, 2026
The file command identifies a file's type from its contents, not from the filename extension.
Syntax
file [options] file...Common cases
file notes.txt # ASCII text
file /bin/ls # ELF 64-bit executable
file photo.jpg # JPEG image data
file archive.gz # gzip compressed dataHow it works: magic numbers
In Linux the name extension means nothing: a file called
data.txtmay be an image.filelooks at the first bytes (called the magic number) and matches them against a signature database:\x7fELFat the start means an ELF executable,\xff\xd8means JPEG,\x1f\x8bmeans gzip. If no signature is recognised,filedecides whether the data is text or binary.
Used in
You need this in the lesson Reading text. The theory is the chapter Reading and editing text.
See also
cat, head, tail, The ls command.
Try it
Open the sandbox: a real throwaway Linux terminal in your browser. Run the commands above by hand - the container is deleted when you leave.