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
Usage examples
View attributes
stat ./report.txtThe default report shows metadata including timestamps and file identity.
Show size in bytes
stat -c '%s' ./report.txtOnly 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.txtThe 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.