Fundamentals 4 min read

Master Linux ‘file’ Command: Identify Types, MIME, and Links in Seconds

This guide explains how the Linux file utility determines file types, shows useful options like brief output, MIME detection, reading filenames from a list, custom delimiters, and inspecting symbolic links, with clear command examples.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Linux ‘file’ Command: Identify Types, MIME, and Links in Seconds

The Linux file utility determines a file’s type by examining its header information rather than relying on the file extension, and can also reveal the file’s encoding.

Examples

Example 1: Default usage

file book.pdf
delete.pdf: PDF document, version 1.3
file book
delete: PDF document, version 1.3

Both commands show that the presence or absence of an extension does not affect the result.

Example 2: Suppress filename

file -b book.pdf
PDF document, version 1.3

The -b (brief) option displays only the file type description.

Example 3: Show MIME type

file -i delete.pdf
delete.pdf: application/pdf; charset=binary

The -i option outputs the MIME type.

Example 4: Read filenames from a file

cat hello.txt
sunset.jpg
file -f hello.txt
sunset.jpg: JPEG image data, JFIF standard 1.01

The -f option tells file to read filenames from the specified file.

Example 5: Custom output format

file -F " === " sunset.jpg
=== JPEG image data, JFIF standard 1.01

This demonstrates a custom delimiter, though its practical use is limited.

Example 6: Inspect symbolic links

file a.jpg
a.jpg: symbolic link to `sunset.jpg'
file -L a.jpg
a.jpg: JPEG image data, JFIF standard 1.01

Without -L, file reports the link itself; with -L, it follows the link and shows the target file’s type.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

file commandfile type detectionUnix utilities
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.