Navigation and files

Command file

Determine file type

Linux · Bash examples · commands run on the selected server

When to use file

Use file to identify a file from its contents rather than trusting its extension. This helps inspect downloads, archives and unknown server files before choosing a viewer or extraction tool.

Syntax

file [OPTIONS] FILE…

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

-b
Do not print the file name before the result.
-i
Show MIME-type and encoding.
-L
Determine the type of object pointed to by a symbolic link.

Usage examples

Determine file type

file ./report.pdf

The result describes the detected format; a filename ending in PDF alone does not prove the contents are PDF.

Check MIME-type

file --mime-type ./report.pdf

The MIME type is useful when checking upload handling or web-server content types.

View multiple file types

file ./README.md ./archive.tar.gz

Both files are inspected in one invocation, with each result associated with its filename.

Notes and limitations

  • A type is determined by content and signatures, not just by extension.
  • The result does not confirm the safety of the file and does not replace verification of its origin.

Common questions and troubleshooting

Does file guarantee that a download is safe?

No. Format detection is not malware analysis, signature verification or an integrity check. Verify checksums or trusted signatures separately.

Why is a text file reported simply as data?

The file may contain binary bytes, an unusual encoding or insufficient identifying content. Check size and encoding without executing the file.

Further help

Options vary by version and distribution. Check the installed documentation with this command: man file.