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.
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.3Both 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.3The -b (brief) option displays only the file type description.
Example 3: Show MIME type
file -i delete.pdf
delete.pdf: application/pdf; charset=binaryThe -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.01The -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.01This 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.01Without -L, file reports the link itself; with -L, it follows the link and shows the target file’s type.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
