file command in Linux with examples (original) (raw)
Last Updated : 11 Jul, 2025
The '**file' command in Linux is a vital utility for determining the type of a file. It identifies file types by examining their content rather than their file extensions, making it an indispensable tool for users who work with various file formats. The file type can be displayed in a **human-readable format (e.g., **ASCII text) or as a **MIME type (e.g., '**text/plain; charset=us-ascii'). The file command tests each argument provided to categorize it accurately.
How the 'file' Command Works
It has three sets of tests as follows:
- **filesystem test: This test is based on the result which returns from a '**stat' system call. The program verifies that if the file is empty, or if it's some sort of special file. This test causes the file type to be printed.
- **magic test: These tests are used to check for files with data in particular fixed formats.
- **language test: This test search for particular strings which can appear anywhere in the first few blocks of a file.
**Syntax
file [option] [filename]
**Example of 'file' Command
You can use the '**file' command with various files to determine their types:
file email.py # Displays type of 'email.py'
file name.jpeg # Displays type of 'name.jpeg'
file Invoice.pdf # Displays type of 'Invoice.pdf'
file exam.ods # Displays type of 'exam.ods'
file videosong.mp4 # Displays type of 'videosong.mp4'
