1 .\" $NetBSD: stat.1,v 1.40 2017/09/20 08:57:02 wiz Exp $
3 .\" Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Andrew Brown and Jan Schaumann.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
36 .Nd display file status
55 utility displays information about the file pointed to by
57 Read, write, or execute permissions of the named file are not required, but
58 all directories listed in the pathname leading to the file must be
60 If no argument is given,
62 displays information about the file descriptor for standard input.
66 only the target of the symbolic link is printed.
67 If the given argument is not a symbolic link and the
69 option is not specified,
71 will print nothing and exit with an error.
74 option is specified, the output is canonicalized by following every symlink
75 in every component of the given path recursively.
77 will resolve both absolute and relative paths, and return the absolute pathname
80 In this case, the argument does not need to be a symbolic link.
82 The information displayed is obtained by calling
84 with the given argument and evaluating the returned structure.
85 The default format displays the
101 fields, in that order.
103 The options are as follows:
104 .Bl -tag -width XFXformatXXX
110 immediately after each pathname that is a directory, an
113 after each that is executable, an at sign
115 after each symbolic link, a percent sign
117 after each whiteout, an equal sign
119 after each socket, and a vertical bar
121 after each that is a FIFO.
127 Display information using the specified format.
130 section for a description of valid formats.
136 The information reported by
138 will refer to the target of
140 if file is a symbolic link, and not to
148 Do not force a newline to appear at the end of each piece of output.
150 Suppress failure messages if calls to
157 error messages are automatically suppressed.
159 Display raw information.
160 That is, for all the fields in the stat-structure,
161 display the raw, numerical value (for example, times in seconds since the
164 Display information in
166 suitable for initializing variables.
169 suppress error messages.
170 This is equivalent to specifying
172 FMT="st_dev=%d st_ino=%i st_mode=%#p st_nlink=%l st_uid=%u st_gid=%g"
173 FMT="$FMT st_rdev=%r st_size=%z st_atime=%Sa st_mtime=%Sm st_ctime=%Sc"
174 FMT="$FMT st_birthtime=%SB st_blksize=%k st_blocks=%b"
175 stat -t %s -f "$FMT" .
177 Note that if you use a timeformat that contains embedded whitespace or shell
178 meta-characters you will need to include appropriate quoting so the
180 output remains valid.
182 Display timestamps using the specified format.
186 with the extension that %f prints nanoseconds if available.
190 Display information in a more verbose way as known from some Linux
194 Format strings are similar to
196 formats in that they start with
198 are then followed by a sequence of formatting characters, and end in
199 a character that selects the field of the struct stat which is to be
203 is immediately followed by one of
209 then a newline character, a tab character, a percent character,
210 or the current file number is printed, otherwise the string is
211 examined for the following:
213 Any of the following optional flags:
216 Selects an alternate output form for string, octal and hexadecimal output.
217 String output will be encoded in
220 Non-zero octal output will have a leading zero.
221 Non-zero hexadecimal output will have
225 Asserts that a sign indicating whether a number is positive or negative
226 should always be printed.
227 Non-negative numbers are not usually printed with a sign.
229 Aligns string output to the left of the field, instead of to the right.
231 Sets the fill character for left padding to the 0 character, instead of
234 Reserves a space at the front of non-negative signed output fields.
237 overrides a space if both are used.
240 Then the following fields:
243 An optional decimal digit string specifying the minimum field width.
245 An optional precision composed of a decimal point
247 and a decimal digit string that indicates the maximum string length,
248 the number of digits to appear after the decimal point in floating point
249 output, or the minimum number of digits to appear in numeric output.
251 An optional output format specifier which is one of
259 These represent signed decimal output, octal output, unsigned decimal
260 output, hexadecimal output, floating point output, and string output,
262 Some output formats do not apply to all fields.
263 Floating point output only applies to timespec fields (the
270 The special output specifier
272 may be used to indicate that the output, if
273 applicable, should be in string format.
274 May be used in combination with
279 format with the extension that %f prints nanoseconds if available.
281 Display actual device name.
283 Display group or user name.
296 Insert a `` -> '' into the output.
297 Note that the default output format for
299 is a string, but if specified explicitly, these four characters are
303 An optional sub field specifier (high, middle, or low).
313 It can be one of the following:
319 .Bl -tag -compact -width door
321 Major number for devices
324 bits from the string form of permissions or the file
326 bits from the numeric forms
328 The long output form of file type
330 Directory path of the file, similar to what
334 File size, rounded to the nearest gigabyte
340 .Bl -tag -compact -width door
344 bits from the string form of permissions or the
349 bits from the numeric forms
351 File size, rounded to the nearest megabyte
357 .Bl -tag -compact -width door
359 Minor number for devices
363 bits from the string form of permissions or the
368 bits from the numeric forms
372 style output character for file type (the use of
376 Base filename of the file, similar to what
380 File size, rounded to the nearest kilobyte
384 A required field specifier, being one of the following:
396 File type and permissions
399 Number of hard links to
403 User-id and group-id of
406 .Pq Fa st_uid , st_gid .
408 Device number for character and block device special files
413 was last accessed or modified, or when the inode was last changed, or
414 the birth time of the inode
415 .Pq Fa st_atime , st_mtime , st_ctime , st_birthtime .
422 Number of blocks allocated for
426 Optimal file system I/O operation block size
430 The following five field specifiers are not drawn directly from the
431 data in struct stat, but are:
434 The name of the file.
436 The absolute pathname corresponding to the file.
438 The file type, either as in
440 or in a more descriptive form if the sub field specifier
444 The target of a symbolic link.
447 .Dq Ar major , Ns Ar minor
448 from the rdev field for character or block
449 special devices and gives size output for all others.
455 and the field specifier are required.
456 Most field specifiers default to
458 as an output form, with the
477 If no options are specified, the default format is
478 "%d %i %Sp %l %Su %Sg %r %z \e"%Sa\e" \e"%Sm\e" \e"%Sc\e" \e"%SB\e" %k %b %#Xf %N".
479 .Bd -literal -offset indent
481 0 78852 -rw-r--r-- 1 root wheel 0 0 "Jul 8 10:26:03 2004" "Jul 8 10:26:03 2004" "Jul 8 10:28:13 2004" "Jan 1 09:00:00 1970" 16384 0 0 /tmp/bar
484 This example produces output very similar to that from
488 displays the time in a different format, and
490 sometimes adds one or more spaces after the comma in
491 .Dq Ar major , Ns Ar minor
493 .Bd -literal -offset indent
494 > stat -f "%7i %6b %-11Sp %3l %-17Su %-17Sg %9Z %Sm %N%SY" /tmp/bar
495 78852 0 -rw-r--r-- 1 root wheel 0 Jul 8 10:26:03 2004 /tmp/bar
497 > find /tmp/bar -ls -exit
498 78852 0 -rw-r--r-- 1 root wheel 0 Jul 8 2004 /tmp/bar
501 This example produces output very similar to that from
505 adjusts the column spacing differently when listing multiple files,
508 adds at least one space after the comma in
509 .Dq Ar major , Ns Ar minor
511 .Bd -literal -offset indent
512 > stat -f "%-11Sp %l %Su %Sg %Z %Sm %N%SY" /tmp/bar
513 -rw-r--r-- 1 root wheel 0 Jul 8 10:26:03 2004 /tmp/bar
516 -rw-r--r-- 1 root wheel 0 Jul 8 10:26:03 2004 /tmp/bar
519 Given a symbolic link
528 .Bd -literal -offset indent
530 lrwxrwxrwx 1 jschauma cs 1 Apr 24 16:37:28 2002 /tmp/foo@ -> /
533 drwxr-xr-x 16 root wheel 512 Apr 19 10:57:54 2002 /tmp/foo/
536 To initialize some shell-variables, you could use the
539 .Bd -literal -offset indent
541 % eval set `stat -s .cshrc`
542 % echo $st_size $st_mtime
546 $ eval $(stat -s .profile)
547 $ echo $st_size $st_mtime
551 In order to get a list of the kind of files including files pointed to if the
552 file is a symbolic link, you could use the following format:
553 .Bd -literal -offset indent
554 $ stat -f "%N: %HT%SY" /tmp/*
555 /tmp/bar: Symbolic Link -> /tmp/foo
556 /tmp/output25568: Regular File
558 /tmp/foo: Symbolic Link -> /
561 In order to get a list of the devices, their types and the major and minor
562 device numbers, formatted with tabs and linebreaks, you could use the
564 .Bd -literal -offset indent
565 stat -f "Name: %N%n%tType: %HT%n%tMajor: %Hr%n%tMinor: %Lr%n%n" /dev/*
573 Type: Character Device
578 In order to determine the permissions set on a file separately, you could use
579 the following format:
580 .Bd -literal -offset indent
581 > stat -f "%Sp -> owner=%SHp group=%SMp other=%SLp" .
582 drwxr-xr-x -> owner=rwx group=r-x other=r-x
585 In order to determine the three files that have been modified most recently,
586 you could use the following format:
587 .Bd -literal -offset indent
588 > stat -f "%m%t%Sm %N" /tmp/* | sort -rn | head -3 | cut -f2-
589 Apr 25 11:47:00 2002 /tmp/blah
590 Apr 25 10:36:34 2002 /tmp/bar
591 Apr 24 16:47:35 2002 /tmp/foo
594 User names, group names, and file names that contain spaces
595 or other special characters may be encoded in
600 .Bd -literal -offset indent
601 > ln -s 'target with spaces' 'link with spaces'
602 > stat -f "%#N%#SY" 'link with spaces'
603 link\eswith\esspaces -> target\eswith\esspaces
624 utility was written by
626 .Aq atatat@NetBSD.org .
627 This man page was written by
629 .Aq jschauma@NetBSD.org .