Mastering Linux stat: Inspect File Details and Filesystem Information
This guide explains the Linux stat command, its syntax and options, and provides step‑by‑step examples showing how to display detailed file metadata and filesystem information, with clear explanations of each output field.
Overview
The stat command in Linux displays detailed information about a file or directory, including size, permissions, timestamps, and the underlying filesystem.
Syntax
Basic usage:
stat [options] filename_or_directoryCommon Options
-f: Show information about the filesystem containing the file instead of the file itself.
Example 1 – View File Details
Command: stat demo.txt Sample output (illustrated below) and explanation:
File: the name of the file ( demo.txt).
Size: file size in bytes (e.g., 665).
Blocks: number of allocated blocks (e.g., 8).
IO Block: preferred I/O block size (e.g., 4096).
Device: device identifier (e.g., fc01h/64513d).
Inode: inode number (e.g., 1051650).
Links: number of hard links (e.g., 1).
Access: permission bits (e.g., 0664), owner UID and GID (e.g., 508).
Access time: last read timestamp.
Modify time: last content modification timestamp.
Change time: last status change timestamp.
Example 2 – View Filesystem Information
Using the -f option shows details about the filesystem that holds the file rather than the file itself: stat -f demo.txt The output includes filesystem type, block size, total/available blocks, and more, as illustrated below.
These examples demonstrate how stat can be used for troubleshooting, auditing file attributes, and gathering filesystem statistics.
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.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
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.
