Home·Terminal commands

stat

Files and directories

Usage

stat [file]

Shows the inode record — size, permission bits, owner and the three timestamps; the format flag is -c on GNU but -f on BSD, where the GNU -f means something else entirely.

Common flags

FlagMeaning
-cGNU: choose the output format, as in -c %s
-fGNU: describe the filesystem. On BSD and macOS -f is the format string
-LFollow symlinks and report the target
-xBSD and macOS: verbose, labelled output
--printfGNU: like -c but adds no newline

Examples

stat -c '%s %n' notes.md

Size and name (GNU).

stat -f '%z %N' notes.md

The same two values on macOS or BSD.

stat notes.md

Full record: size, mode, owner and the timestamps.

Moving, deleting and finding. Some of these do not ask twice, which is why -i becomes a habit.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does stat do?

Shows the inode record — size, permission bits, owner and the three timestamps; the format flag is -c on GNU but -f on BSD, where the GNU -f means something else entirely.

Q. How do I type it?

stat [file] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

5 are listed here; the full set is in man stat. This command sits under Files and directories.

Related commands

man page: man stat