coreutils: stat invocation

1 
1 14.3 ‘stat’: Report file or file system status
1 ==============================================
1 
1 ‘stat’ displays information about the specified file(s).  Synopsis:
1 
1      stat [OPTION]... [FILE]...
1 
1    With no option, ‘stat’ reports all information about the given files.
1 But it also can be used to report the information of the file systems
1 the given files are located on.  If the files are links, ‘stat’ can also
1 give information about the files the links point to.
1 
1    Due to shell aliases and built-in ‘stat’ functions, using an
1 unadorned ‘stat’ interactively or in a script may get you different
1 functionality than that described here.  Invoke it via ‘env’ (i.e., ‘env
1 stat ...’) to avoid interference from the shell.
1 
1 ‘-L’
1 ‘--dereference’
1      Change how ‘stat’ treats symbolic links.  With this option, ‘stat’
1      acts on the file referenced by each symbolic link argument.
1      Without it, ‘stat’ acts on any symbolic link argument directly.
1 
1 ‘-f’
1 ‘--file-system’
1      Report information about the file systems where the given files are
1      located instead of information about the files themselves.  This
1      option implies the ‘-L’ option.
1 
1 ‘--cached=MODE’
1      Control how attributes are read from the file system; if supported
1      by the system.  This allows one to control the trade-off between
1      freshness and efficiency of attribute access, especially useful
1      with remote file systems.  MODE can be:
1 
1      ‘always’
1           Always read the already cached attributes if available.
1 
1      ‘never’
1           Always sychronize with the latest file system attributes.
1           This also mounts automounted files.
1 
1      ‘default’
1           Leave the caching behavior to the underlying file system.
1 
1 ‘-c’
1 ‘--format=FORMAT’
1      Use FORMAT rather than the default format.  FORMAT is automatically
1      newline-terminated, so running a command like the following with
1      two or more FILE operands produces a line of output for each
1      operand:
1           $ stat --format=%d:%i / /usr
1           2050:2
1           2057:2
1 
1 ‘--printf=FORMAT’
1      Use FORMAT rather than the default format.  Like ‘--format’, but
1      interpret backslash escapes, and do not output a mandatory trailing
1      newline.  If you want a newline, include ‘\n’ in the FORMAT.
1      Here’s how you would use ‘--printf’ to print the device and inode
1      numbers of ‘/’ and ‘/usr’:
1           $ stat --printf='%d:%i\n' / /usr
1           2050:2
1           2057:2
1 
1 ‘-t’
1 ‘--terse’
1      Print the information in terse form, suitable for parsing by other
1      programs.
1 
1      The output of the following commands are identical and the
1      ‘--format’ also identifies the items printed (in fuller form) in
1      the default format.  Note the format string would include another
1      ‘%C’ at the end with an active SELinux security context.
1           $ stat --format="%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %W %o" ...
1           $ stat --terse ...
1 
1      The same illustrating terse output in ‘--file-system’ mode:
1           $ stat -f --format="%n %i %l %t %s %S %b %f %a %c %d" ...
1           $ stat -f --terse ...
1 
1    The valid FORMAT directives for files with ‘--format’ and ‘--printf’
1 are:
1 
1    • %a - Access rights in octal (note ‘#’ and ‘0’ printf flags)
1    • %A - Access rights in human readable form
1    • %b - Number of blocks allocated (see ‘%B’)
1    • %B - The size in bytes of each block reported by ‘%b’
1    • %C - The SELinux security context of a file, if available
1    • %d - Device number in decimal
1    • %D - Device number in hex
1    • %f - Raw mode in hex
1    • %F - File type
1    • %g - Group ID of owner
1    • %G - Group name of owner
1    • %h - Number of hard links
1    • %i - Inode number
1    • %m - Mount point (See note below)
1    • %n - File name
1    • %N - Quoted file name with dereference if symbolic link (see below)
1    • %o - Optimal I/O transfer size hint
1    • %s - Total size, in bytes
1    • %t - Major device type in hex (see below)
1    • %T - Minor device type in hex (see below)
1    • %u - User ID of owner
1    • %U - User name of owner
1    • %w - Time of file birth, or ‘-’ if unknown
1    • %W - Time of file birth as seconds since Epoch, or ‘0’
1    • %x - Time of last access
1    • %X - Time of last access as seconds since Epoch
1    • %y - Time of last data modification
1    • %Y - Time of last data modification as seconds since Epoch
1    • %z - Time of last status change
1    • %Z - Time of last status change as seconds since Epoch
1 
1    The ‘%a’ format prints the octal mode, and so it is useful to control
1 the zero padding of the output with the ‘#’ and ‘0’ printf flags.  For
1 example to pad to at least 3 wide while making larger numbers
1 unambiguously octal, you can use ‘%#03a’.
1 
1    The ‘%N’ format can be set with the environment variable
1 ‘QUOTING_STYLE’.  If that environment variable is not set, the default
1 value is ‘shell-escape-always’.  Valid quoting styles are:
1 ‘literal’
1      Output strings as-is; this is the same as the ‘-N’ or ‘--literal’
1      option.
1 ‘shell’
1      Quote strings for the shell if they contain shell metacharacters or
1      would cause ambiguous output.  The quoting is suitable for
1      POSIX-compatible shells like ‘bash’, but it does not always work
1      for incompatible shells like ‘csh’.
1 ‘shell-always’
1      Quote strings for the shell, even if they would normally not
1      require quoting.
1 ‘shell-escape’
1      Like ‘shell’, but also quoting non-printable characters using the
1      POSIX proposed ‘$''’ syntax suitable for most shells.
1 ‘shell-escape-always’
1      Like ‘shell-escape’, but quote strings even if they would normally
1      not require quoting.
1 ‘c’
1      Quote strings as for C character string literals, including the
1      surrounding double-quote characters; this is the same as the ‘-Q’
1      or ‘--quote-name’ option.
1 ‘escape’
1      Quote strings as for C character string literals, except omit the
1      surrounding double-quote characters; this is the same as the ‘-b’
1      or ‘--escape’ option.
1 ‘clocale’
1      Quote strings as for C character string literals, except use
1      surrounding quotation marks appropriate for the locale.
1 ‘locale’
1      Quote strings as for C character string literals, except use
1      surrounding quotation marks appropriate for the locale, and quote
1      'like this' instead of "like this" in the default C locale.  This
1      looks nicer on many displays.
1 
1    The ‘%t’ and ‘%T’ formats operate on the st_rdev member of the
1 stat(2) structure, and are only defined for character and block special
1 files.  On some systems or file types, st_rdev may be used to represent
1 other quantities.
1 
1    The ‘%W’, ‘%X’, ‘%Y’, and ‘%Z’ formats accept a precision preceded by
1 a period to specify the number of digits to print after the decimal
1 point.  For example, ‘%.3X’ outputs the access timestamp to millisecond
1 precision.  If a period is given but no precision, ‘stat’ uses 9 digits,
1 so ‘%.X’ is equivalent to ‘%.9X’.  When discarding excess precision,
1 timestamps are truncated toward minus infinity.
1 
1      zero pad:
1        $ stat -c '[%015Y]' /usr
1        [000001288929712]
1      space align:
1        $ stat -c '[%15Y]' /usr
1        [     1288929712]
1        $ stat -c '[%-15Y]' /usr
1        [1288929712     ]
1      precision:
1        $ stat -c '[%.3Y]' /usr
1        [1288929712.114]
1        $ stat -c '[%.Y]' /usr
1        [1288929712.114951834]
1 
1    The mount point printed by ‘%m’ is similar to that output by ‘df’,
1 except that:
1    • stat does not dereference symlinks by default (unless ‘-L’ is
1      specified)
1    • stat does not search for specified device nodes in the file system
1      list, instead operating on them directly
1    • stat outputs the alias for a bind mounted file, rather than the
1      initial mount point of its backing device.  One can recursively
1      call stat until there is no change in output, to get the current
1      base mount point
1 
1    When listing file system information (‘--file-system’ (‘-f’)), you
1 must use a different set of FORMAT directives:
1 
1    • %a - Free blocks available to non-super-user
1    • %b - Total data blocks in file system
1    • %c - Total file nodes in file system
1    • %d - Free file nodes in file system
1    • %f - Free blocks in file system
1    • %i - File System ID in hex
1    • %l - Maximum length of file names
1    • %n - File name
1    • %s - Block size (for faster transfers)
1    • %S - Fundamental block size (for block counts)
1    • %t - Type in hex
1    • %T - Type in human readable form
1 
1    Timestamps are listed according to the time zone rules specified by
1 the ‘TZ’ environment variable, or by the system default rules if ‘TZ’ is
1 not set.  ⇒Specifying the Time Zone with ‘TZ’ (libc)TZ Variable.
1 
1    An exit status of zero indicates success, and a nonzero value
1 indicates failure.
1