Files & folders

Linux file command

Identify a file’s type by examining its contents and metadata.

Availability: Common Linux commands; shell built-ins and external implementations may differ by distribution.中文

Syntax

file [OPTION]... FILE...

Examples

Identify a file from its contents and metadata.

file archive.tar.gz

Print only the MIME type information.

file --mime-type image.png

Parameters, options and clauses

Option / clauseDescription
-b, --briefDo not prepend filenames to output.
-i, --mimeOutput MIME type information.
-L, --dereferenceFollow symbolic links.
-k, --keep-goingContinue checking after the first match.
-z, --uncompressTry to inspect compressed files.
-s, --special-filesRead block or character special files.
Safety note

Review a command and its target before running it. Commands that alter files, services, accounts, disks, permissions or databases may be difficult to reverse. Test in a safe environment and keep backups.

Official reference ↗Back to directory