Navigation and files

Command stat

Show detailed information about a file

Linux · Bash examples · commands run on the selected server

When to use stat

Use stat when you need precise metadata such as byte size, mode, owner and timestamps. It is useful for checking permissions and comparing files without reading their entire contents.

Syntax

stat [OPTIONS] FILE…

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

-c FORMAT
Custom output format in GNU stat.
-L
Show attributes of the target of a symbolic link.
-f
Display information about the file system.

Usage examples

View attributes

stat ./report.txt

The default report shows metadata including timestamps and file identity.

Show size in bytes

stat -c '%s' ./report.txt

Only the byte count is printed, which is easier to consume than a formatted listing.

View permissions and owner

stat -c '%a %U:%G %n' ./report.txt

The output combines numeric mode, owner, group and path for a compact permission check.

Notes and limitations

  • GNU stat options and formats differ from BSD stat on macOS.
  • ctime records a metadata change, not necessarily the file creation time.

Common questions and troubleshooting

Why do stat and du show different sizes?

Logical file length and allocated disk space are different quantities. Sparse files and filesystem allocation can make those values diverge.

Do these formatting options work on macOS?

These examples use GNU stat on Linux. The BSD stat interface on macOS has different formatting flags.

Further help

Options vary by version and distribution. Check the installed documentation with this command: man stat.