Stat Command Overview

The stat command displays detailed file or filesystem status information. It’s commonly used by developers and sysadmins to inspect metadata such as permissions, ownership, timestamps, and filesystem-specific attributes.

Synopsis

stat [OPTION]... FILE...

Key Options

  • -c, --format=FORMAT
    Use a custom format string (see FORMAT below).
  • -f, --file-system
    Display information about the filesystem instead of the file itself.
  • -L, --dereference
    Follow symlinks (show info for the target).
  • --printf=FORMAT
    Like -c but without trailing newline.
  • -t, --terse
    Print in terse (single-line) format.

Default Output Example

$ stat example.txt
  File: example.txt
  Size: 1024            Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d      Inode: 264457      Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/   alice)   Gid: ( 1000/   alice)
Access: 2025-06-13 14:22:10.000000000 +0200
Modify: 2025-06-12 09:15:45.000000000 +0200
Change: 2025-06-12 09:15:45.000000000 +0200
 Birth: 2025-06-10 08:00:00.000000000 +0200

Field Breakdown

FieldDescription
FilePath to the file being inspected.
SizeTotal size in bytes.
BlocksNumber of 512-byte blocks allocated.
IO BlockFilesystem I/O block (optimal transfer) size in bytes.
regular file / directory / …File type.
DeviceDevice number in hex/decimal.
InodeInode number (unique file system identifier).
LinksNumber of hard links.
AccessFile permissions (octal and symbolic), then UID and GID with names.
AccessLast access timestamp (atime).
ModifyLast data modification timestamp (mtime).
ChangeLast status change timestamp (ctime).
BirthCreation timestamp (if supported by filesystem).

Custom Formatting

You can extract specific fields using -c/--format. For example:

stat -c 'Size: %s bytes%nModified: %y%nPerm: %A' example.txt

Common Format Sequences

SpecifierMeaning
%nFile name
%sTotal size in bytes
%bNumber of blocks
%FFile type
%iInode number
%hNumber of hard links
%UUser name of owner
%GGroup name of owner
%aAccess rights in octal
%AAccess rights in human-readable form (-rw-r--r--)
%xTime of last access
%yTime of last modification
%zTime of last status change

Example: Filesystem Status

$ stat -f /home
  File: "/home"
    ID: 74ef3f7d5e83b4e4 Namelen: 255     Type: ext2/ext3
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 244190560   Free: 178103412   Available: 167035968
Inodes: Total: 62464000    Free: 62123412

This shows filesystem‐level metrics such as total blocks, free blocks, inode counts, and the filesystem type.


Use man stat for the full list of options and format specifiers.

Categories: Bash