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
| Flag | Description |
|---|---|
-b, --brief | Do not prepend filenames to output lines. |
-i, --mime | Output mime type strings instead of human-readable descriptions. |
-L, --dereference | Causes symlinks to be followed. |
-z, --uncompress | Try to look inside compressed files. |
Real-world Examples
-
Determine the type of a file:
file image.jpg -
Check a file without extension:
file unknown_file -
Get the MIME type of a file:
file -i document.pdf