stat Command

The stat command in Linux is used to display detailed information about a file or file system. This includes file size, permissions, ownership, timestamps (access, modify, change), and inode number. It's a valuable tool for system administrators and developers to inspect file metadata.

Syntax

stat [OPTION]... FILE...

Description

stat displays information about the given FILE(s). If FILE is a symbolic link, by default, stat displays information about the file the link points to. Use the -L option to display information about the link itself.

Common uses include:

  • Viewing file permissions and ownership
  • Checking file access, modification, and change times
  • Retrieving inode numbers and device information
  • Inspecting file system details (with -f option)

Common Options

Option Description
-L, --dereference Follow links
-f, --file-system Display file system status instead of file status
-c, --format=FORMAT Use the specified FORMAT instead of the default; interpret backslash escapes
-t, --terse Print the information in terse form
--printf=FORMAT Like --format, but interpret backslash escapes and do not output trailing newline

Examples

Display file status

stat myfile.txt

Displays detailed status information for 'myfile.txt'.

Display file system status

stat -f /home/user

Displays status information about the file system where '/home/user' resides.

Display octal permissions

stat -c %a myfile.txt

Displays the octal permissions of 'myfile.txt'.

Display file size and name

stat -c "%s %n" myfile.txt

Displays the size and name of 'myfile.txt'.

Display modification time

stat -c %y myfile.txt

Displays the last modification time of 'myfile.txt'.

See also