1 .\" $NetBSD: stat.1,v 1.11 2003/05/08 13:07:10 wiz 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.
17 .\" 3. All advertising materials mentioning features or use of this software
18 .\" must display the following acknowledgement:
19 .\" This product includes software developed by the NetBSD
20 .\" Foundation, Inc. and its contributors.
21 .\" 4. Neither the name of The NetBSD Foundation nor the names of its
22 .\" contributors may be used to endorse or promote products derived
23 .\" from this software without specific prior written permission.
25 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 .\" POSSIBILITY OF SUCH DAMAGE.
45 .Nd display file status
49 .Op Fl f Ar format | Fl l | r | s | x
58 utility displays information about the file pointed to by
60 Read, write or execute permissions of the named file are not required, but
61 all directories listed in the path name leading to the file must be
63 If no argument is given,
65 displays information about the file descriptor for standard input.
69 only the target of the symbolic link is printed.
70 If the given argument is not a symbolic link,
72 will print nothing and exit with an error.
74 The information displayed is obtained by calling
76 with the given argument and evaluating the returned structure.
78 The options are as follows:
79 .Bl -tag -width indent
85 immediately after each pathname that is a directory,
88 after each that is executable,
91 after each symbolic link,
100 after each that is a FIFO.
110 The information reported by
112 will refer to the target of
114 if file is a symbolic link, and not to
118 Do not force a newline to appear at the end of each piece of output.
120 Suppress failure messages if calls to
127 error messages are automatically suppressed.
129 Display information using the specified format.
132 section for a description of valid formats.
138 Display raw information.
139 That is, for all the fields in the
142 display the raw, numerical value (for example, times in seconds since the
145 Display information in
147 suitable for initializing variables.
149 Display information in a more verbose way as known from some
153 Display timestamps using the specified format.
159 Format strings are similar to
161 formats in that they start with
163 are then followed by a sequence of formatting characters, and end in
164 a character that selects the field of the
166 which is to be formatted.
169 is immediately followed by one of
173 then a newline character, a tab character, a percent character,
174 or the current file number is printed, otherwise the string is
175 examined for the following:
177 Any of the following optional flags:
178 .Bl -tag -width indent
180 Selects an alternate output form for octal and hexadecimal output.
181 Non-zero octal output will have a leading zero, and non-zero
182 hexadecimal output will have
186 Asserts that a sign indicating whether a number is positive or negative
187 should always be printed.
188 Non-negative numbers are not usually printed
191 Aligns string output to the left of the field, instead of to the right.
193 Sets the fill character for left padding to the
195 character, instead of a space.
197 Reserves a space at the front of non-negative signed output fields.
200 overrides a space if both are used.
203 Then the following fields:
204 .Bl -tag -width indent
206 An optional decimal digit string specifying the minimum field width.
208 An optional precision composed of a decimal point
210 and a decimal digit string that indicates the maximum string length,
211 the number of digits to appear after the decimal point in floating point
212 output, or the minimum number of digits to appear in numeric output.
214 An optional output format specifier which is one of
215 .Cm D , O , U , X , F ,
218 These represent signed decimal output, octal output, unsigned decimal
219 output, hexadecimal output, floating point output, and string output,
221 Some output formats do not apply to all fields.
222 Floating point output only applies to
230 The special output specifier
232 may be used to indicate that the output, if
233 applicable, should be in string format.
234 May be used in combination with:
235 .Bl -tag -width indent
241 Display actual device name.
248 Display group or user name.
264 Note that the default output format
267 is a string, but if specified explicitly, these four characters are
271 An optional sub field specifier (high, middle, low).
278 It can be one of the following:
279 .Bl -tag -width indent
283 specifies the major number for devices from
289 bits for permissions from the string form of
293 bits from the numeric forms of
295 and the long output form of
300 specifies the minor number for devices from
306 bits for permissions from the string form of
313 bits from the numeric forms of
317 style output character for file type when used with
321 for this is optional).
327 bits for permissions from the
328 string output form of
335 bits for the numeric forms of
339 A required field specifier, being one of the following:
340 .Bl -tag -width indent
349 File type and permissions.
351 Number of hard links to
354 User ID and group ID of
358 Device number for character and block device special files.
362 was last accessed or modified, of when the inode was last changed, or
363 the birth time of the inode.
369 Number of blocks allocated for
372 Optimal file system I/O operation block size.
374 User defined flags for
377 Inode generation number.
380 The following four field specifiers are not drawn directly from the
384 .Bl -tag -width indent
386 The name of the file.
388 The file type, either as in
390 or in a more descriptive form if the
396 The target of a symbolic link.
402 field for character or block
403 special devices and gives size output for all others.
409 and the field specifier are required.
410 Most field specifiers default to
412 as an output form, with the
429 .Ex -std stat readlink
431 Given a symbolic link
440 .Bd -literal -offset indent
441 \*[Gt] stat -F /tmp/foo
442 lrwxrwxrwx 1 jschauma cs 1 Apr 24 16:37:28 2002 /tmp/foo@ -\*[Gt] /
444 \*[Gt] stat -LF /tmp/foo
445 drwxr-xr-x 16 root wheel 512 Apr 19 10:57:54 2002 /tmp/foo/
448 To initialize some shell variables, you could use the
451 .Bd -literal -offset indent
453 % eval set `stat -s .cshrc`
454 % echo $st_size $st_mtimespec
458 $ eval $(stat -s .profile)
459 $ echo $st_size $st_mtimespec
463 In order to get a list of file types including files pointed to if the
464 file is a symbolic link, you could use the following format:
465 .Bd -literal -offset indent
466 $ stat -f "%N: %HT%SY" /tmp/*
467 /tmp/bar: Symbolic Link -\*[Gt] /tmp/foo
468 /tmp/output25568: Regular File
470 /tmp/foo: Symbolic Link -\*[Gt] /
473 In order to get a list of the devices, their types and the major and minor
474 device numbers, formatted with tabs and linebreaks, you could use the
476 .Bd -literal -offset indent
477 stat -f "Name: %N%n%tType: %HT%n%tMajor: %Hr%n%tMinor: %Lr%n%n" /dev/*
485 Type: Character Device
490 In order to determine the permissions set on a file separately, you could use
491 the following format:
492 .Bd -literal -offset indent
493 \*[Gt] stat -f "%Sp -\*[Gt] owner=%SHp group=%SMp other=%SLp" .
494 drwxr-xr-x -\*[Gt] owner=rwx group=r-x other=r-x
497 In order to determine the three files that have been modified most recently,
498 you could use the following format:
499 .Bd -literal -offset indent
500 \*[Gt] stat -f "%m%t%Sm %N" /tmp/* | sort -rn | head -3 | cut -f2-
501 Apr 25 11:47:00 2002 /tmp/blah
502 Apr 25 10:36:34 2002 /tmp/bar
503 Apr 24 16:47:35 2002 /tmp/foo
506 To display a file's modification time:
507 .Bd -literal -offset indent
508 \*[Gt] stat -f %m /tmp/foo
512 To display the same modification time in a readable format:
513 .Bd -literal -offset indent
514 \*[Gt] stat -f %Sm /tmp/foo
518 To display the same modification time in a readable and sortable format:
519 .Bd -literal -offset indent
520 \*[Gt] stat -f %Sm -t %Y%m%d%H%M%S /tmp/foo
524 To display the same in UTC:
525 .Bd -literal -offset indent
527 $ TZ= stat -f %Sm -t %Y%m%d%H%M%S /tmp/foo
549 utility was written by
551 .Aq atatat@NetBSD.org .
552 This man page was written by
554 .Aq jschauma@NetBSD.org .