The file utility identifies file types from magic numbers and metadata. libmagic lets other programs detect types without spawning the file command.
Overview
The file program implements the familiar Unix file command: given paths, it reports what each file likely is by consulting magic data rather than relying only on filename extensions. It recognizes thousands of file types and follows the System V style of reading rules from magic databases, with extensions such as tar archive awareness.
Modern releases refactor core logic into libmagic, a library other applications can link or import to identify types in-process instead of fork-and-execing the standalone command. Capabilities include CDF parsing, MIME and ASCII encoding handling, compressed content inspection, and recognition of formats such as JSON, CSV, ELF, and tar.
The package is the standard file command on Linux, BSD, and related systems. Magic rules are maintained in a structured directory and aggregated into the runtime database developers install on the system.
Optional packaging targets include AmigaOS cross-builds with variant C runtimes, but the everyday role of the product remains type detection for shell scripts, file managers, and security tooling on Unix-like hosts.
Key features
- Magic-number file identification
- libmagic embeddable API
- Compressed file introspection
- MIME and encoding detection
- CDF and ELF recognition
- JSON and CSV awareness
- Configurable magic database
Use cases
- Shell scripts classifying unknown files
- Programs detecting types in-process
- Mail and security pipeline triage
- Build systems validating artifacts