Skip to main content

file

Explanation

The file command is used to determine the file type. Linux does not rely heavily on file extensions to determine what a file is; instead, file examines the contents of a file (looking for "magic numbers") to identify its type (e.g., ASCII text, JPEG image, ELF executable).

Basic Syntax

file [OPTION]... FILE...

Common Flags and Options

FlagDescription
-b, --briefDo not prepend filenames to output lines.
-i, --mimeOutput mime type strings instead of human-readable descriptions.
-L, --dereferenceCauses symlinks to be followed.
-z, --uncompressTry to look inside compressed files.

Real-world Examples

  1. Determine the type of a file:

    file image.jpg
  2. Check a file without extension:

    file unknown_file
  3. Get the MIME type of a file:

    file -i document.pdf