Back to the command reference

file

FilesBeginner In simulator In real Linux

Determine a file type

Name: file: determine file type

You can practise it right away in the simulator, and use it in real Linux mode too.

Description

file determines a file's type by looking at its content (its "magic" bytes) rather than its extension. It recognises executables, scripts, images, archives, text encodings and much more.

That matters on Linux, where extensions are only a convention and may be missing or wrong.

Syntax

file [OPTION]... FILE...

Common options

-b / --briefDon't prefix with the file name
-i / --mimePrint the MIME type
-L / --dereferenceLook at what symbolic links point to
-z / --uncompressLook inside compressed files
-s / --special-filesRead device files too (to see the file system on /dev/sda1)
-f / --files-from FILERead the names to check from FILE, one per line

Examples

  • $ file /bin/ls

    An executable program

    Explain
  • $ file photo.jpg notes.txt

    Check several files at once

    Explain

Related