stat: Report file or file system status
stat displays information about the specified file(s). Synopsis:
stat [option]… [file]…
With no option,
stat reports all information about the given files.
But it also can be used to report the information of the file systems the
given files are located on. If the files are links,
also give information about the files the links point to.
Due to shell aliases and built-in
stat functions, using an
stat interactively or in a script may get you
different functionality than that described here. Invoke it via
env stat …) to avoid interference
from the shell.
stat treats symbolic links.
With this option,
stat acts on the file referenced
by each symbolic link argument.
stat acts on any symbolic link argument directly.
Report information about the file systems where the given files are located instead of information about the files themselves. This option implies the -L option.
Use format rather than the default format. format is automatically newline-terminated, so running a command like the following with two or more file operands produces a line of output for each operand:
$ stat --format=%d:%i / /usr 2050:2 2057:2
Use format rather than the default format. Like --format, but interpret backslash escapes, and do not output a mandatory trailing newline. If you want a newline, include ‘\n’ in the format. Here’s how you would use --printf to print the device and inode numbers of / and /usr:
$ stat --printf='%d:%i\n' / /usr 2050:2 2057:2
Print the information in terse form, suitable for parsing by other programs.
The output of the following commands are identical and the --format also identifies the items printed (in fuller form) in the default format. Note the format string would include another ‘%C’ at the end with an active SELinux security context.
$ stat --format="%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %W %o" ... $ stat --terse ...
The same illustrating terse output in --file-system mode:
$ stat -f --format="%n %i %l %t %s %S %b %f %a %c %d" ... $ stat -f --terse ...
The valid format directives for files with --format and --printf are:
The ‘%a’ format prints the octal mode, and so it is useful to control the zero padding of the output with the ‘#’ and ‘0’ printf flags. For example to pad to at least 3 wide while making larger numbers unambiguously octal, you can use ‘%#03a’.
The ‘%t’ and ‘%T’ formats operate on the st_rdev member of the stat(2) structure, and are only defined for character and block special files. On some systems or file types, st_rdev may be used to represent other quantities.
The ‘%W’, ‘%X’, ‘%Y’, and ‘%Z’ formats accept a
precision preceded by a period to specify the number of digits to
print after the decimal point. For example, ‘%.3X’ outputs the
last access time to millisecond precision. If a period is given but no
stat uses 9 digits, so ‘%.X’ is equivalent to
‘%.9X’. When discarding excess precision, time stamps are truncated
toward minus infinity.
zero pad: $ stat -c '[%015Y]' /usr  space align: $ stat -c '[%15Y]' /usr [ 1288929712] $ stat -c '[%-15Y]' /usr [1288929712 ] precision: $ stat -c '[%.3Y]' /usr [1288929712.114] $ stat -c '[%.Y]' /usr [1288929712.114951834]
The mount point printed by ‘%m’ is similar to that output
df, except that:
When listing file system information (--file-system (-f)), you must use a different set of format directives:
Time stamps are listed according to the time zone rules specified by
TZ environment variable, or by the system default rules if
TZ is not set. See Specifying the Time Zone
TZ in The GNU C Library Reference Manual.
An exit status of zero indicates success, and a nonzero value indicates failure.