๐ŸŽ New User? Get 20% off your first purchase with code NEWUSER20 ยท โšก Instant download ยท ๐Ÿ”’ Secure checkout Register Now โ†’
Menu

Categories

๐Ÿ’ก File Viewing & Searching September 27, 2026 15

Linux Command: file

Determine the type of a file

Terminal โ€” File Viewing & Searching
Command
$ file report.pdf
Output
report.pdf: PDF document, version 1.7

The file command determines the type of a file by examining its contents rather than its extension. It uses magic number databases, filesystem tests, and language tests to identify files. file is essential because Linux does not rely on file extensions for type determination. A file named photo.jpg might actually be a text file, and a file without an extension could be a valid executable. file reads the actual content to make an accurate determination. The command can identify hundreds of file types including text encodings, image formats, compressed archives, executables, scripts, documents, and more. It also detects MIME types useful for web servers and email handling.

Syntax

file [OPTION] FILE...

Key Options

  • -i โ€” Output MIME type instead of description
  • -b โ€” Brief mode - omit filename from output
  • -z โ€” Look inside compressed files
  • -L โ€” Follow symbolic links
  • -f โ€” Read filenames from a file
  • -s โ€” Read block/character special files

Examples

Identify file type

file report.pdf

Output: report.pdf: PDF document, version 1.7

Check MIME type

file -i image.png

Output: image.png: image/png; charset=binary

Check multiple files

file *

Pro Tips

  • Always check archives with file before extracting. A file named archive.tar.gz might not actually be a gzip file.
  • Use file -i to get MIME types when configuring web server content types or email attachments.
  • file uses heuristics and can occasionally misidentify files. It reads file headers, not the entire content.

Learn more: Full file reference โ†’

Share this tip