Quick take: The stat command shows detailed metadata about a file — size, permissions, owner, inode, and the access, modify, and change times. stat file prints it all; -c lets you format specific fields.

Introduction

The stat command displays everything the filesystem knows about a file — far more than ls -l. It reveals the inode number, exact size, permission bits in both symbolic and octal form, and the three distinct timestamps Linux keeps, making it invaluable for debugging permissions and timing issues.

Syntax

The basic syntax of the stat command is:

stat [OPTIONS] FILE...

Common Options and Parameters

The most useful options and parameters for the stat command:

OptionDescription
-c FORMATPrint only the fields you specify (custom format).
-fShow filesystem status instead of file status.
-tTerse output on a single line.
-LFollow symbolic links to their target.
%n %s %aFormat specifiers: name, size, octal permissions.
%U %G %iOwner, group, inode number.
%x %y %zAccess, modify, and change timestamps.

Practical Examples

Real stat commands you can run today:

# Full metadata for a file
stat report.txt
# Just the octal permissions
stat -c '%a' report.txt
# Size in bytes
stat -c '%s' report.txt
# Owner and group
stat -c '%U:%G' report.txt
# Filesystem info for a path
stat -f /home
# Custom one-line summary
stat -c '%n is %s bytes, perms %a' *.conf

Tips and Best Practices

  • stat shows three times: access (read), modify (content changed), and change (metadata changed) — useful for forensic and build questions.
  • stat -c '%a' gives octal permissions instantly, handy in scripts that check file modes.
  • Use stat -f to inspect the filesystem (type, block size, free space) behind a path.

Final Thoughts

stat is the detailed counterpart to ls -l, exposing the inode, exact size, octal permissions, and all three timestamps a file carries. Its -c format makes it scriptable for extracting a single field. When you need to know precisely what the filesystem records about a file, stat is the answer.

FAQ: stat Command in Linux

What is the difference between stat and ls -l?+

ls -l gives a compact summary, while stat shows much more: the inode number, exact byte size, permissions in octal and symbolic form, and the separate access, modify, and change timestamps.

What are the three timestamps stat shows?+

Access (atime) is when the file was last read, Modify (mtime) is when its contents last changed, and Change (ctime) is when its metadata such as permissions last changed.

How do I get a file's permissions in octal?+

Use stat -c '%a' filename, which prints just the octal mode like 644 — convenient for scripts and comparisons.

How do I check filesystem information with stat?+

Use stat -f /path to show the filesystem type, block size, and free space for the filesystem containing that path.

How do I show specific fields only?+

Use -c with format specifiers, for example stat -c '%n %s %U' file to print the name, size, and owner. See the manual for the full list of specifiers.

Need help with Linux servers or infrastructure?

Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.

Hire Me for Support