Linux stat command

Updated: 03/13/2021 by Computer Hope
stat command

On Unix-like operating systems, the stat command displays the detailed status of a particular file or a file system.

This page describes the GNU/Linux version of stat.

Syntax

stat [OPTION]... FILE...

Options

-f, --filesystem display filesystem status instead of file status
-c, --format=FORMAT use the specified FORMAT instead of the default
-L, --dereference follow links
-Z, --context print the SELinux security context
-t, --terse print the information in terse form
--help display this help and exit
--version output version information and exit

The valid format sequences for files (without --filesystem):

%A Access rights in human readable form
%a Access rights in octal
%B The size in bytes of each block reported by '%b'
%b Number of blocks allocated (see %B)
%C SELinux security context string
%D Device number in hex
%d Device number in decimal
%F File type
%f Raw mode in hex
%G Group name of owner
%g Group ID of owner
%h Number of hard links
%i Inode number
%N Quoted File name with dereference if symbolic link
%n File name
%o IO block size
%s Total size, in bytes
%T Minor device type in hex
%t Major device type in hex
%U Username of owner
%u User ID of owner
%X Time of last access as seconds since Epoch
%x Time of last access
%Y Time of last modification as seconds since Epoch
%y Time of last modification
%Z Time of last change as seconds since Epoch
%z Time of last change

Valid format sequences for file systems:

%a Free blocks available to non-superuser
%b Total data blocks in file system
%c Total file nodes in file system
%C SELinux security context string
%d Free file nodes in file system
%f Free blocks in file system
%i File System id in hex
%l Maximum length of file names
%n File name
%s Optimal transfer block size
%T Type in human readable form
%t Type in hex

Examples

stat index.htm

Reports the status of file index.htm, displaying results similar to the following output:

File: `index.htm'
Size: 17137 Blocks: 40 IO Block: 8192 regular file
Device: 8h/8d Inode: 23161443 Links: 1
Access: (0644/-rw-r--r--) 
Uid: (17433/comphope) Gid: ( 32/ www)
Access: 2007-04-03 09:20:18.000000000 -0600
Modify: 2007-04-01 23:13:05.000000000 -0600
Change: 2007-04-02 
16:36:21.000000000 -0600
stat -f /dev/sda

With the -f option, stat can return the status of an entire file system. Here, it returns the status of the first hard disk. Output resembles the following:

  File: "/dev/sda"
    ID: 0        Namelen: 255     Type: tmpfs
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 2560       Free: 2560       Available: 2560
Inodes: Total: 126428     Free: 125966
stat --format "%A" /var/log/syslog

Display only the access restrictions, in human-readable form, of the system log /var/log/syslog. Output resembles the following:

-rw-r-----

...which indicates that the file is readable and writable by root, readable by the owning group (in this case the admin group), and not accessible at all by others.

ls — List the contents of a directory or directories.