1 .\" $NetBSD: stat.1,v 1.28 2010/04/05 21:25:01 joerg Exp $
3 .\" Copyright (c) 2002 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.
38 .Nd display file status
42 .Op Fl f Ar format | Fl l | r | s | x
51 utility displays information about the file pointed to by
53 Read, write, or execute permissions of the named file are not required, but
54 all directories listed in the pathname leading to the file must be
56 If no argument is given,
58 displays information about the file descriptor for standard input.
62 only the target of the symbolic link is printed.
63 If the given argument is not a symbolic link and the
65 option is not specified,
67 will print nothing and exit with an error.
70 option is specified, the output is canonicalized by following every symlink
71 in every component of the given path recursively.
73 will resolve both absolute and relative paths, and return the absolute pathname
76 In this case, the argument does not need to be a symbolic link.
78 The information displayed is obtained by calling
80 with the given argument and evaluating the returned structure.
81 The default format displays the
98 fields, in that order.
100 The options are as follows:
101 .Bl -tag -width indent
107 immediately after each pathname that is a directory,
110 after each that is executable,
113 after each symbolic link,
122 after each that is a FIFO.
132 The information reported by
134 will refer to the target of
136 if file is a symbolic link, and not to
139 If the link is broken or the target does not exist,
142 and report information about the link.
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 information using the specified format.
162 section for a description of valid formats.
168 Display raw information.
169 That is, for all the fields in the
172 display the raw, numerical value (for example, times in seconds since the
175 Display information in
178 suitable for initializing variables.
180 Display information in a more verbose way as known from some
184 Display timestamps using the specified format.
190 Format strings are similar to
192 formats in that they start with
194 are then followed by a sequence of formatting characters, and end in
195 a character that selects the field of the
197 which is to be formatted.
200 is immediately followed by one of
204 then a newline character, a tab character, a percent character,
205 or the current file number is printed, otherwise the string is
206 examined for the following:
208 Any of the following optional flags:
209 .Bl -tag -width indent
211 Selects an alternate output form for octal and hexadecimal output.
212 Non-zero octal output will have a leading zero, and non-zero
213 hexadecimal output will have
217 Asserts that a sign indicating whether a number is positive or negative
218 should always be printed.
219 Non-negative numbers are not usually printed
222 Aligns string output to the left of the field, instead of to the right.
224 Sets the fill character for left padding to the
226 character, instead of a space.
228 Reserves a space at the front of non-negative signed output fields.
231 overrides a space if both are used.
234 Then the following fields:
235 .Bl -tag -width indent
237 An optional decimal digit string specifying the minimum field width.
239 An optional precision composed of a decimal point
241 and a decimal digit string that indicates the maximum string length,
242 the number of digits to appear after the decimal point in floating point
243 output, or the minimum number of digits to appear in numeric output.
245 An optional output format specifier which is one of
246 .Cm D , O , U , X , F ,
249 These represent signed decimal output, octal output, unsigned decimal
250 output, hexadecimal output, floating point output, and string output,
252 Some output formats do not apply to all fields.
253 Floating point output only applies to
261 The special output specifier
263 may be used to indicate that the output, if
264 applicable, should be in string format.
265 May be used in combination with:
266 .Bl -tag -width indent
272 Display actual device name.
279 Display group or user name.
295 Note that the default output format
298 is a string, but if specified explicitly, these four characters are
302 An optional sub field specifier (high, middle, low).
309 It can be one of the following:
310 .Bl -tag -width indent
314 specifies the major number for devices from
320 bits for permissions from the string form of
324 bits from the numeric forms of
326 and the long output form of
331 specifies the minor number for devices from
337 bits for permissions from the string form of
344 bits from the numeric forms of
348 style output character for file type when used with
352 for this is optional).
358 bits for permissions from the
359 string output form of
366 bits for the numeric forms of
370 A required field specifier, being one of the following:
371 .Bl -tag -width indent
382 File type and permissions
385 Number of hard links to
389 User ID and group ID of
392 .Pq Fa st_uid , st_gid .
394 Device number for character and block device special files
399 was last accessed or modified, or when the inode was last changed, or
400 the birth time of the inode
401 .Pq Fa st_atime , st_mtime , st_ctime , st_birthtime .
408 Number of blocks allocated for
412 Optimal file system I/O operation block size
415 User defined flags for
418 Inode generation number
422 The following five field specifiers are not drawn directly from the
426 .Bl -tag -width indent
428 The name of the file.
430 The absolute pathname corresponding to the file.
432 The file type, either as in
434 or in a more descriptive form if the
440 The target of a symbolic link.
446 field for character or block
447 special devices and gives size output for all others.
453 and the field specifier are required.
454 Most field specifiers default to
456 as an output form, with the
473 .Ex -std stat readlink
475 If no options are specified, the default format is
476 "%d %i %Sp %l %Su %Sg %r %z \e"%Sa\e" \e"%Sm\e" \e"%Sc\e" \e"%SB\e" %k %b %#Xf %N".
477 .Bd -literal -offset indent
479 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
482 Given a symbolic link
491 .Bd -literal -offset indent
492 \*[Gt] stat -F /tmp/foo
493 lrwxrwxrwx 1 jschauma cs 1 Apr 24 16:37:28 2002 /tmp/foo@ -\*[Gt] /
495 \*[Gt] stat -LF /tmp/foo
496 drwxr-xr-x 16 root wheel 512 Apr 19 10:57:54 2002 /tmp/foo/
499 To initialize some shell variables, you could use the
502 .Bd -literal -offset indent
504 % eval set `stat -s .cshrc`
505 % echo $st_size $st_mtimespec
509 $ eval $(stat -s .profile)
510 $ echo $st_size $st_mtimespec
514 In order to get a list of file types including files pointed to if the
515 file is a symbolic link, you could use the following format:
516 .Bd -literal -offset indent
517 $ stat -f "%N: %HT%SY" /tmp/*
518 /tmp/bar: Symbolic Link -\*[Gt] /tmp/foo
519 /tmp/output25568: Regular File
521 /tmp/foo: Symbolic Link -\*[Gt] /
524 In order to get a list of the devices, their types and the major and minor
525 device numbers, formatted with tabs and linebreaks, you could use the
527 .Bd -literal -offset indent
528 stat -f "Name: %N%n%tType: %HT%n%tMajor: %Hr%n%tMinor: %Lr%n%n" /dev/*
536 Type: Character Device
541 In order to determine the permissions set on a file separately, you could use
542 the following format:
543 .Bd -literal -offset indent
544 \*[Gt] stat -f "%Sp -\*[Gt] owner=%SHp group=%SMp other=%SLp" .
545 drwxr-xr-x -\*[Gt] owner=rwx group=r-x other=r-x
548 In order to determine the three files that have been modified most recently,
549 you could use the following format:
550 .Bd -literal -offset indent
551 \*[Gt] stat -f "%m%t%Sm %N" /tmp/* | sort -rn | head -3 | cut -f2-
552 Apr 25 11:47:00 2002 /tmp/blah
553 Apr 25 10:36:34 2002 /tmp/bar
554 Apr 24 16:47:35 2002 /tmp/foo
557 To display a file's modification time:
558 .Bd -literal -offset indent
559 \*[Gt] stat -f %m /tmp/foo
563 To display the same modification time in a readable format:
564 .Bd -literal -offset indent
565 \*[Gt] stat -f %Sm /tmp/foo
569 To display the same modification time in a readable and sortable format:
570 .Bd -literal -offset indent
571 \*[Gt] stat -f %Sm -t %Y%m%d%H%M%S /tmp/foo
575 To display the same in UTC:
576 .Bd -literal -offset indent
578 $ TZ= stat -f %Sm -t %Y%m%d%H%M%S /tmp/foo
600 utility was written by
602 .Aq atatat@NetBSD.org .
603 This man page was written by
605 .Aq jschauma@NetBSD.org .