Stat (system call)

stat() is a Unix system call that queries the file system for metadata about a file (including special files such as directories). The metadata contains many fields including type, size, ownership, permissions and timestamps.

For example, the ls command uses this system call to retrieve timestamps:

  • mtime: when last modified (ls -l)
  • atime: when last accessed (ls -lu)
  • ctime: when last status changed (ls -lc)

stat() appeared in Version 1 Unix. It is among the few original Unix system calls to change, with Version 4's addition of group permissions and larger file size.

Since at least 2004, the same-named shell command stat has been available for Linux to expose features of the system call via a command-line interface.