Fundamentals 3 min read

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.

Open Source Linux
Open Source Linux
Open Source Linux
Master the Linux ‘file’ Command: Identify File Types Quickly

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 text

Example 3

Display the MIME type of a file:

# file -i readme.txt
readme.txt: text/plain; charset=us-ascii
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.

Linuxfile commandfile type detection
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

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.