8 Stat Command Examples in Linux

Linux stat command

1) Stat command with no arguments

$ stat file1.txt
Stat-command-default-output
  • File : This shows the name of the file.
  • Size : Size of the file in bytes.
  • Block : Number of blocks allocated to the file.
  • IO Block : This is the byte size of every block.
  • Device : The device number in hexadecimal or decimal format.
  • Inode : This is the inode number of the file.
  • Links : Number of hard links associated with the file.
  • Access : File permissions either in symbolic or numeric format.
  • Uid : User ID & name of the owner.
  • Gid : Group ID & name of the owner.
  • Context : SeLinux security context
  • File type : Shows what type the file is (Whether a regular file, symbolic link etc).
  • Access : Shows the last time the file was accessed.
  • Modify : Shows the last time the contents of the file were changed.
  • Change : Shows the last time a file’s metadata e.g permissions & ownership was changed.

2) View information about multiple files

$ stat file1.txt file2.pdf
Stat-command-with-multiple-files

3) Display file system status

$ stat -f /home
Stat-command-filesystem-linux

4) Display information in terse form

$ stat -t file1.txt
Stat-command-with-terse-form

5) Enable following of symbolic links

$ stat /usr/share/zoneinfo/America/Cayman
stat-command-symlink-file
$ stat -L /usr/share/zoneinfo/America/Cayman
stat-command-with-derefernce

6) Format sequencing

$ stat --printf='%in' file1.txt
Format-Stat-Command-output
$ stat --printf='%a:%un' file1.txt
Stat-access-rights-userid-linux
$ stat --format='%a:%F' file1.txt
Additional-operand-stat-command
  • %a Displays the access rights in octal format.
  • %A Displays the access rights in a human readable format.
  • %b This is the number of blocks allocated (see %B).
  • %B the size in bytes of each block reported by %b.
  • %C Shows the SELinux security context string.
  • %d Displays the device number in a decimal format.
  • %D The device number in hexadecimal format.
  • %f Displays the raw mode in hexadecimal.
  • %F Displays the file type.
  • %g Prints the group ID of owner.
  • %G Prints the group name of owner.
  • %h Displays the number of hard links.
  • %i Prints out the inode number.
  • %m Prints the mount point.
  • %n Displays the file name of the file
  • %N Shows quoted file name with dereference if symbolic link
  • %o Prints the optimal I/O transfer size hint.
  • %s total size, in bytes.
  • %t major device type in hex, for character/block device special files
  • %T minor device type in hex, for character/block device special files
  • %u Shows the user ID of owner.
  • %U Prints the username of owner.
  • %w Reveals the time of file birth, human-readable; — if unknown.
  • %W Prints the time of file birth, seconds since Epoch; 0 if unknown.
  • %x The time of last access, human-readable.
  • %X The time of last access, seconds since Epoch.
  • %y Displays the last time of last modification, human-readable.
  • %Y Prints the time of last modification, seconds since Epoch.
  • %z This is the time of last change, human-readable.
  • %Z The time of last change, seconds since Epoch.

7) Getting help with stat command

$ stat --help
Stats-Command-help
$ man stat
man-page-stat-command

8) Checking the version of stat

$ stat --version
stat-command-version

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store