The Stat command can be used as a utility to view a file or file system, retrieving information such as file type, octal and human-readable access permissions, last access, SELinux security context strings, file birth time, and so on. One option is to specify a custom format to display the information, as follows!
The simplest way to display stat is to display file size, block, IO block, file type, inode value, number of links, etc., such as viewing /var/log/syslog file:
$ stat /var/log/syslog
The stat command treats the input file as a normal file, if you want to display the file system state instead of the file state:
$ stat -f /var/log/syslog
You can also provide a directory/file system as a parameter:
$ stat -f /
Because Linux supports links, such as symbolic links/hard links. Some files may have 1 or more links, which can be traced using stat:
$ stat -L /
Stst-specific or custom formats can be used instead of the default format, and the c option can be used to specify the format, printing a newline character each time a format sequence is used. Alternatively, you can explain and turn off the print trailing newline option by enabling backslash escape sequences, if printf is needed in formatting to print newline \n:
# stat --printf='%U\n%G\n%C\n%z\n' /var/log/secure
%U: owner's user name, %G: owner's group name, %C: SELinux security context string, %z: time of last state change, human-readable.
Stat is used to print information in concise form:
$ stat -t /var/log/syslog
The shell may have its own version of stat, see the shell documentation for details on the options it supports. To see all the sequences of acceptable output formats, see the stat man page:
$ man stat