• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero® Blog

NameHero® Blog

Web Hosting Tips & Resources From NameHero

  • Hosting
    • Web Hosting
    • WordPress Hosting
    • WooCommerce Hosting
    • Enterprise Hosting
  • VPS
    • VPS Hosting
    • Flex VPS
  • Reseller
  • Email
  • Gaming
  • Domains
  • Website Builder
  • Account
  • Blog Home
  • Categories
  • Authors

The Linux Stat Command: Your Key to Advanced File Information

CJ Saathoff

Published on: January 17, 2024

Categories: Linux Command Line, VPS Hosting 0

On Linux systems, everything things is made of up files and folders. The stat command holds the key to unraveling a wealth of information about your files and directories like permissions, ownership, size, or timestamps. Join us on a journey through the depths of file metadata as we delve into the versatile capabilities of the stat command. From basic usage to advanced features, this powerhouse utility empowers Linux enthusiasts, sysadmins, and curious minds to gain unparalleled insights into their file systems.

  • Introduction:
  • Basic Usage
  • Understanding The Basic Output
  • Options And Flags
    • Mode
    • Format Options
  • Conclusion:

Introduction:

The stat command is part of the GNU coreutils package. Linux is often used as a generic term to refer to any system that uses the Linux kernel. Though may disagree with referring to the whole stack as just Linux, instead they feel it is more appropriate to use GNU/Linux. This is because, without the applications on top of the kernel, Linux would be a shell of what it is. GNU provides many of the base programs, applications, and libraries that when bundled with the Linux kernel do we get something resembling the the dynamic environment we interact with daily.

Now, armed with this context, let’s explore the stat command in detail. As we unravel its purpose and delve into its functionalities, we’ll uncover how this command becomes an indispensable tool for users navigating the intricacies of file metadata on a Linux system. From unraveling basic file attributes to wielding advanced features, the stat command invites us into the core of Linux’s file-centric universe.

Basic Usage

At its core, the stat command is a versatile tool designed to provide quick and essential information about files and directories. Its basic usage can significantly enhance your ability to navigate and understand the structure of your Linux system.

The basic syntax of the stat command is straightforward. Simply type stat followed by the path to the file or directory you want to inspect. For example:

stat /path/to/file

It is also possible to run the stat command on more than one file using wildcards.

stat /path/to/files/*

Understanding The Basic Output

Here is the basic Output from the stat command on a file called example.txt.
Note: the stat command defaults may vary slightly between different distributions.

  File: example.txt
  Size: 169486    	Blocks: 336        IO Block: 4096   regular file
Device: 0,39	Inode: 1371398     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/      cj)   Gid: ( 1000/      cj)
Access: 2024-01-03 14:30:11.220415381 -0500
Modify: 2023-12-18 14:59:33.070992691 -0500
Change: 2023-12-19 14:00:46.540768169 -0500
 Birth: 2023-12-18 14:59:33.066992608 -0500

File Information (Lines 1-2):

  • File: The name of the file or directory being analyzed.
  • Size: The size of the file generally will be in bytes.
  • Blocks: The number of disk blocks allocated for the file.
  • IO Block: The block size used for disk I/O operations.
  • Type: Indicates whether the item is a regular file, directory, symbolic link, etc.

Device and Inode Information (Line 3):

  • Device: The device identifier you might encounter either decimal or hexadecimal representations for the device numbers
  • Inode: The inode number, a unique identifier for the file or directory.
  • Links: The number of hard links to the file.

Access Control (Line 4):

  • Access: Displays the file permissions in octal notation and the corresponding human-readable form.
  • Uid: The user ID of the file owner and corresponding username.
  • Gid: The group ID of the group owner and corresponding group name.

Timestamps (Lines 5-8)

  • Access: The last time the file was accessed.
  • Modify: The last time the file content was modified.
  • Change: The last time the file metadata was changed (e.g., permissions).
  • Birth: The creation time of the file. Note: This may be unavailable on some file system

Options And Flags

Let’s look at the options and flags or the stat command.

-L: Tells stat to follow links
-f: display file system status instead of file status
–cached=MODE: specify how to use cached attributes; useful on remote file systems.
-c=FORMAT: use the specified FORMAT instead of the default.
–printf=FORMAT: like –format, but interpret backslash escapes, and do not output a mandatory trailing newline; if you want a newline, add \n in FORMAT
-t: print the information in terse form
–help: display help text and exits
–version: display version information and exits

Mode

The MODE argument of the –cached flag has three options

  • always: will use cached attributes if available
  • never: will try to synchronize with the latest attributes
  • default: will leave it up to the underlying file system.

Format Options

It could be for scripting, readability, user preference, or something else entirely but if the default option isn’t enough then all you have to do is pass the format options to the stat command. Below is the list of the different options for the stat command.

Note: When using the format options make sure to wrap the options in single or double parentheses.

The valid format sequences for files (without –file-system):

%a     permission bits in octal (note '#' and '0' printf flags)
%A     permission bits and file type in human readable form
%b     number of blocks allocated (see %B)
%B     the size in bytes of each block reported by %b
%C     SELinux security context string
%d     device number in decimal (st_dev)
%D     device number in hex (st_dev)
%Hd    major device number in decimal
%Ld    minor device number in decimal
%f     raw mode in hex
%F     file type
%g     group ID of owner
%G     group name of owner
%h     number of hard links
%i     inode number
%m     mount point
%n     file name
%N     quoted file name with dereference if symbolic link
%o     optimal I/O transfer size hint
%s     total size, in bytes
%r     device type in decimal (st_rdev)
%R     device type in hex (st_rdev)
%Hr    major device type in decimal, for character/block device special files
%Lr    minor device type in decimal, for character/block device special files
%t     major device type in hex, for character/block device special files
%T     minor device type in hex, for character/block device special files
%u     user ID of owner
%U     user name of owner
%w     time of file birth, human-readable; - if unknown
%W     time of file birth, seconds since Epoch; 0 if unknown
%x     time of last access, human-readable
%X     time of last access, seconds since Epoch
%y     time of last data modification, human-readable
%Y     time of last data modification, seconds since Epoch
%z     time of last status change, human-readable
%Z     time of last status change, seconds since Epoch

Valid format sequences for file systems:

%a     free blocks available to non-superuser
%b     total data blocks in file system
%c     total file nodes in file system
%d     free file nodes in file system
%f     free blocks in file system
%i     file system ID in hex
%l     maximum length of filenames
%n     file name
%s     block size (for faster transfers)
%S     fundamental block size (for block counts)
%t     file system type in hex
%T     file system type in human readable form

–terse is equivalent to the following FORMAT:

%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %W %o %C

–terse –file-system is equivalent to the following FORMAT:

%n %i %l %t %s %S %b %f %a %c %d

Conclusion:

As Linux enthusiasts, sysadmins, and curious minds delve into the world of file metadata, the stat command emerges as a key ally. The Linux stat command serves as an invaluable tool for users navigating the landscape of file metadata on Linux systems. From its basic usage, providing essential information about files and directories, to its advanced features that allow users to tailor output formats and explore file systems.

CJ Saathoff

Embracing a lifelong passion for technology since childhood, CJ delved into the intricate workings of systems, captivated by the desire to understand the unknown. This innate curiosity led to his discovery of Linux, a revelation that resonated deeply. With more than 7 years of on the job experience, he’s honed his technical skills as a Geek and Senior Linux Systems Administrator.

Related Posts

How To Create Groups In Linux

In Linux, you can bunch users into groups and manage their access to resources collectively. This helps with managing permissions.

How to Merge a Git Branch to Master

Check out our guide on how to merge a git branch to the master branch, as well as some assumptions and considerations.

Ubuntu Time Essentials: From Time Zones to NTP

In this guide, we discuss the process of setting date, time zone, and time, as well as configuring NTP both from the GUI and the command line.

Pwd Command In Linux: The Complete Guide

Learn how the PWD command can be used and some examples of handy ways to utilize it on the command line interface in Linux.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!


Most Popular Posts

NameHero’s Recommended WordPress Plugin and Theme Setup (2024)

WordPress Hosting vs. Web Hosting – What’s The Difference?

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • WordPress Tutorials
  • Enterprise Hosting
  • WooCommerce
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • Website Performance
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero® proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • VPS Hosting
  • Flex VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • Email Hosting
  • Game Hosting
  • Domains
  • Website Builder
Help & Support
  • NameHero Blog
  • NameHero Gaming Blog
  • Support
  • Help Center
  • Migrations
  • Affiliates
  • Gaming Affiliates
  • Call 1-855-984-6263
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2025 Name Hero, LLC. All rights reserved.
NameHero® is a registered trademark.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA