stat — Every Fact the Filesystem Holds About a File, and the Timestamp You Cannot Fake

ByLinuxtastic

November 29, 2026

ls -l shows you a summary chosen fifty years ago: a mode string, an owner, a size, one of the file’s timestamps rounded to the minute. The filesystem holds a good deal more than that about every file — three timestamps, often four; the inode number that says whether two names are one file; the number of blocks actually allocated, which is not the size; the device the file lives on — and stat prints all of it, either as a readable block or as exactly the fields you ask for in exactly the order you want them. It is the command for “when did this really change”, “is this file actually using the space it claims”, “are these two names the same file” and, in scripts, for getting a file’s owner, mode or age without parsing ls.

stat f.txt
  File: f.txt
  Size: 6         	Blocks: 8          IO Block: 4096   regular file
Device: 254,0	Inode: 811248      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2026-11-29 20:24:10.112262672 +0000
Modify: 2026-11-29 20:24:10.112262672 +0000
Change: 2026-11-29 20:24:10.112262672 +0000
 Birth: 2026-11-29 20:24:10.112262672 +0000

Top to bottom: the size in bytes and the number of 512-byte blocks allocated to hold it (six bytes still cost one 4 KiB filesystem block, which is eight of them); the device, as major and minor numbers, and the inode number, which together identify the file uniquely on this machine; the link count, which is how many directory entries point at this inode; the permission bits in octal and symbolic form with the numeric and named owner and group; and the timestamps. The second “Access” line is a timestamp, not a permission — an unfortunate reuse of the word that confuses everyone once. Birth is the creation time, recorded by ext4, XFS and Btrfs on any kernel from the last several years and shown as - where the filesystem does not keep it.

Three timestamps, three different questions

Modify (mtime) is when the contents last changed. Change (ctime) is when the inode last changed — contents, but also permissions, owner, link count or name. Access (atime) is when the contents were last read, with a large caveat. Only mtime and atime can be set by a user; ctime is written by the kernel and cannot be backdated, which makes it the one to trust when the question is “has this file been tampered with”. All of this was measured for this page on an ext4 filesystem mounted relatime, which is the default everywhere:

$ echo hello > f.txt; sleep 1; chmod 640 f.txt
$ stat -c '%n  mtime=%y  ctime=%z' f.txt
f.txt  mtime=2026-11-29 20:24:10.112262672  ctime=2026-11-29 20:24:11.220262738
$ sleep 1; cat f.txt >/dev/null; stat -c 'atime=%x' f.txt
atime=2026-11-29 20:24:12.324262804
$ sleep 1; cat f.txt >/dev/null; stat -c 'atime=%x' f.txt
atime=2026-11-29 20:24:12.324262804
$ sleep 1; mv f.txt g.txt; stat -c '%n mtime=%y ctime=%z' g.txt
g.txt mtime=2026-11-29 20:24:10.112262672 ctime=2026-11-29 20:24:14.536262935
$ touch -d '2020-01-01 00:00:00' g.txt; stat -c 'mtime=%y ctime=%z' g.txt
mtime=2020-01-01 00:00:00.000000000 ctime=2026-11-29 20:24:14.540262936

Read it as four facts. chmod moved ctime and left mtime alone, so “modified” in ls -l says nothing about permission changes. The first cat updated atime and the second did not: under relatime the access time is written only if it is older than the modify or change time, or more than a day old, so atime tells you a file was read since it was last written, and nothing finer than that. mv within a filesystem touched ctime (the link changed) and not mtime (the bytes did not). And touch -d happily set mtime to 2020 while ctime recorded the moment it was done — a file with a plausible old mtime and a recent ctime has been handled recently, whatever its mtime claims. Backup tools, rsync and make compare mtime; find -cmin and intrusion checks compare ctime; almost nothing should rely on atime.

Asking for exactly the fields you want

-c FORMAT (or --format=) prints one line per file in the format given, with a newline added; --printf= is the same but interprets \n and \t and adds nothing, for output you control precisely. The sequences worth knowing:

SequencePrints
%n / %NFile name / quoted name, with -> target for a symlink
%sSize in bytes
%b / %BBlocks allocated / size of each in bytes (512): %b × %B is the space actually used
%FType in words: regular file, directory, symbolic link, character special file, socket, fifo
%a / %APermissions in octal / in the ls -l form
%u / %U, %g / %GOwner uid / name, group gid / name; the name is UNKNOWN if the id has no entry
%iInode number
%hHard link count
%d / %DDevice the file is on, decimal / hex; same value means same filesystem
%t / %TFor a device file, its major / minor number in hex
%x %y %z %wAccess, modify, change, birth time, human-readable with nanoseconds and zone
%X %Y %Z %WThe same four as seconds since the epoch (birth is 0 where unknown)
%.19yA precision cuts the field: 19 characters is YYYY-MM-DD HH:MM:SS, %.3y keeps milliseconds
%mMount point the file is under
%CSELinux context, where there is one
$ stat -c '%A %U:%G %s %.19y %n' g.txt
-rw-r----- root:root 6 2020-01-01 00:00:00 g.txt
$ stat --printf='%n\t%s\t%Y\n' g.txt link
g.txt	6	1577836800
link	5	1795983867
$ stat -c '%Y %n' * | sort -n | tail -1          # newest by mtime, correctly, unlike ls -t with odd names
1795983867 sparse.img

Those three lines replace most of the ls -l | awk pipelines ever written, and they do not break on a file name with spaces, a size that pushes the columns about, or a locale that changes the date format. -t prints a terse single line of every field — the form the statx data came in, useful for diffing two files’ metadata and for nothing else.

Size is not space

$ truncate -s 1G sparse.img
$ stat -c '%n size=%s bytes, %b blocks of %B bytes' sparse.img
sparse.img size=1073741824 bytes, 0 blocks of 512 bytes
$ du -h sparse.img; du -h --apparent-size sparse.img
0	sparse.img
1.0G	sparse.img

A sparse file is one whose unwritten regions were never allocated: a gigabyte of size, no blocks. Virtual machine disk images, database preallocations, core dumps and anything made with truncate or fallocate look like this, and the two numbers diverge in the other direction too — a six-byte file occupies a whole 4 KiB block, and a file that was written and then had its contents partially freed can hold blocks its size does not account for. du reports blocks, ls and %s report size, and a directory that “cannot” be as big as du says, or a copy that is suddenly much larger than the original, is almost always this. cp --sparse=always and rsync -S keep the holes; cat and scp fill them in. Disk Space covers the other cases where df and du disagree.

Links, symlinks and directories

$ ln -s g.txt link; stat -c '%n: %F, %s bytes, mode %a' link
link: symbolic link, 5 bytes, mode 777
$ stat -L -c '%n: %F, %s bytes, mode %a' link
link: regular file, 6 bytes, mode 640
$ ln g.txt g2.txt; stat -c '%n: inode %i, %h links' g.txt g2.txt
g.txt: inode 811248, 2 links
g2.txt: inode 811248, 2 links
$ mkdir -p d/a d/b; stat -c '%n: %h links' d
d: 4 links

By default stat describes the symlink itself: five bytes, because that is the length of the string g.txt, and mode 777, because a symlink’s own permissions are never consulted. -L follows it and describes the target. Two names with the same device and inode are one file, which is how you confirm a hard link, and how a backup tool decides not to store a file twice; the link count tells you how many names there are without having to find them (find / -inum 811248 does the finding). A directory’s count is two plus the number of subdirectories — its own entry, its ., and the .. inside each child — so %h on a directory is a free count of its immediate subdirectories. ln is the page on why hard and symbolic links are not variations on one idea; Filesystems is the page on what an inode is.

The filesystem, not the file: stat -f

$ stat -f -c 'type=%T  block size=%S  blocks=%b free=%f avail=%a  inodes=%c free=%d' .
type=ext2/ext3  block size=4096  blocks=66053021 free=62874945 avail=7844084  inodes=16777216 free=16462643

-f switches to the filesystem the path is on and the format sequences change meaning: %T is the type, %S the block size, %b/%f/%a total, free and available-to-non-root blocks, %c/%d total and free inodes. It is df for one path, in whatever form you want, and the inode counts are the ones df -i shows. Two cautions. The type comes from the filesystem’s magic number, and ext4 shares its magic with ext2 and ext3, so an ext4 filesystem is reported as ext2/ext3 — the line above is from an ext4 root; use findmnt -T . -o FSTYPE or df -T when the real type matters. And free and available differ by the reserved blocks (five per cent by default on ext4) that only root may use, which is why a filesystem can be “full” with free space showing.

Device files

$ stat -c '%n: %F, %t:%T major:minor (hex)' /dev/null /dev/vda
/dev/null: character special file, 1:3 major:minor (hex)
/dev/vda: block special file, fe:0 major:minor (hex)

For a device node the interesting fields are the major and minor numbers, which stat prints in hex; fe:0 is 254:0, which is the Device: line in the first example on this page, so the file f.txt lives on /dev/vda. Matching a file’s %D against device nodes’ %t:%T is the long way of answering “which disk is this file on”; df FILE and findmnt -T FILE are the short ways, and The Life of a Block Device is the page on why that question has seven answers.

Common problems

SymptomCauseCheck / fix
A file’s “modified” time is old but something changed itPermissions, owner or name changed, which moves ctime only; or mtime was set with touch -dstat -c '%y %z'; a ctime newer than mtime is the tell
atime never updatesrelatime (default) or noatime mount optionfindmnt -T file -o OPTIONS; do not rely on atime
du and ls -l disagree wildlySparse file, or small files each costing a full blockstat -c '%s %b'; du --apparent-size
stat -f says ext2/ext3 on an ext4 diskShared magic numberfindmnt -o FSTYPE or df -T
Owner shows as UNKNOWN or a bare numberNo account with that uid on this machine (restored backup, container volume, removed user)stat -c '%u' for the number; getent passwd UID to confirm
Symlink shows mode 777 and the wrong sizestat describes the link itselfstat -L
cannot statx 'x': No such file or directory for a symlink that existsOnly with -L: the target is missing (dangling link)stat without -L, then readlink
Birth: -Filesystem does not record creation time (older XFS, some network filesystems), or an old statUse ctime as the oldest reliable bound
Script output misaligned or broken on some filesParsing ls -lstat -c with the fields you need

Quick reference

stat file                                   # everything, readable
stat -c '%y %z' file                        # mtime and ctime: which one moved?
stat -c '%a %U:%G %n' file                  # octal mode, owner, name
stat -c '%s %b' file                        # bytes claimed vs 512-byte blocks used
stat -c '%i %h %n' a b                      # same inode = same file; link count
stat -L file                                # follow a symlink
stat -c '%Y %n' * | sort -n | tail -1       # newest file, safely
stat -c '%.19y %n' *                        # timestamps without nanoseconds
stat --printf='%n\t%s\n' *                  # exact output, your newlines
stat -f -c '%T %a %c' /var                  # filesystem type, free blocks, inodes
stat -c '%t:%T' /dev/sda                    # major:minor, hex
date -d @"$(stat -c %Y file)"               # an epoch field back into a date

Related reading

  • Filesystems — inodes, blocks and journalling: what the fields stat prints are stored in
  • find — -mtime, -cmin, -newer and -inum: searching by the same timestamps and inode numbers
  • ln — why two names with one inode behave the way they do
  • Disk Space — the other cases in which the bytes on disk are not the bytes in the files
  • File Permissions — what the octal and symbolic modes mean, and the setuid, setgid and sticky digits %a includes
  • The Life of a File Descriptor — the deleted-but-open file whose inode stat can no longer reach by name