Linuxlab

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 data

How it works: magic numbers

In Linux the name extension means nothing: a file called data.txt may be an image. file looks at the first bytes (called the magic number) and matches them against a signature database: \x7fELF at the start means an ELF executable, \xff\xd8 means JPEG, \x1f\x8b means gzip. If no signature is recognised, file decides 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.