Master the Linux ‘file’ Command: Identify File Types Quickly
This guide explains how to use the Linux file command to determine a file’s type, describes its useful options, and provides practical examples for displaying MIME types, suppressing filenames, and handling symbolic links.
File: Query File Types
Function Description
The file command can be used to query the type of a specified file, revealing whether it is a binary executable, a shell script, or another format.
File types recognized include directories, shell scripts, English text, binary executables, C source files, generic text files, and DOS executables.
Command Syntax
file [options] [file]Option Meanings
The options are explained below:
-v : Show version information
-z : Attempt to examine compressed files
-L : Follow symbolic links and display the target file type
-i : Show MIME type
-c : Verbose output for debugging or analysis
-b : Brief mode; omit the filename in the output
-f<namefile> : Read a list of filenames from a file
-m : Specify a magic file
Reference Examples
Example 1
Show the file types of all files in /root/test directory:
# file /root/test/*
/root/test/date: directory
/root/test/readme.txt: ASCII text
/root/test/red: symbolic link to `readme.txt`Example 2
Show file type without displaying the filename:
# file -b readme.txt
ASCII textExample 3
Display the MIME type of a file:
# file -i readme.txt
readme.txt: text/plain; charset=us-asciiSigned-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.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
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.
