Identify Any File's Real Type with the file Command
Detect true file types from magic bytes, not from the filename extension.
Run file suspicious-download.dat to print the real type, e.g. 'PE32 executable' or 'gzip compressed data'; add -b for terse output or -i for a MIME type.
01Command
Command
$ file suspicious-download.dat02What it does
file reads the first bytes of a file and matches them against the magic database in /usr/share/misc/magic, so a renamed archive, a script posing as an image or a truncated download are all exposed instantly. It also reports architecture and linkage for executables and character-set information for text. This is the standard first step when inspecting unknown downloads or auditing what a script actually delivered.
03Risk
!Warning: Knowing a file's type does not make it safe — an executable identified as such can still be malware; do not execute unknown binaries.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- file(1) — determine file typeEvidence: Man page documents magic tests and options -b (brief), -i (mime), -L; confirms 'file', '-b' and 'magic' appear in the text.
- file(1) — Debian man pageEvidence: Man page header states 'file — determine file type' and describes MAGIC (the magic tests based on /usr/share/misc/magic); confirms MAGIC and file-identification behavior.
Last verified: 2026-09-19 · Category: Files & Folders