1 .\" $NetBSD: stat.1,v 1.11 2003/05/08 13:07:10 wiz Exp $
2 .\" Copyright (c) 2002 The NetBSD Foundation, Inc.
3 .\" All rights reserved.
5 .\" This code is derived from software contributed to The NetBSD Foundation
6 .\" by Andrew Brown and Jan Schaumann.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\" notice, this list of conditions and the following disclaimer in the
15 .\" documentation and/or other materials provided with the distribution.
16 .\" 3. All advertising materials mentioning features or use of this software
17 .\" must display the following acknowledgement:
18 .\" This product includes software developed by the NetBSD
19 .\" Foundation, Inc. and its contributors.
20 .\" 4. Neither the name of The NetBSD Foundation nor the names of its
21 .\" contributors may be used to endorse or promote products derived
22 .\" from this software without specific prior written permission.
24 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
25 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
28 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 .\" POSSIBILITY OF SUCH DAMAGE.
36 .\" $FreeBSD: src/usr.bin/stat/stat.1,v 1.8 2005/06/14 11:50:53 ru Exp $
44 .Nd display file status
48 .Op Fl f Ar format | Fl l | r | s | x
57 utility displays information about the file pointed to by
59 Read, write or execute permissions of the named file are not required, but
60 all directories listed in the path name leading to the file must be
62 If no argument is given,
64 displays information about the file descriptor for standard input.
68 only the target of the symbolic link is printed.
69 If the given argument is not a symbolic link,
71 will print nothing and exit with an error.
73 The information displayed is obtained by calling
75 with the given argument and evaluating the returned structure.
77 The options are as follows:
78 .Bl -tag -width indent
84 immediately after each pathname that is a directory,
87 after each that is executable,
90 after each symbolic link,
99 after each that is a FIFO.
109 The information reported by
111 will refer to the target of
113 if file is a symbolic link, and not to
117 Do not force a newline to appear at the end of each piece of output.
119 Suppress failure messages if calls to
126 error messages are automatically suppressed.
128 Display information using the specified format.
131 section for a description of valid formats.
137 Display raw information.
138 That is, for all the fields in the
141 display the raw, numerical value (for example, times in seconds since the
144 Display information in
146 suitable for initializing variables.
148 Display information in a more verbose way as known from some
152 Display timestamps using the specified format.
158 Format strings are similar to
160 formats in that they start with
162 are then followed by a sequence of formatting characters, and end in
163 a character that selects the field of the
165 which is to be formatted.
168 is immediately followed by one of
172 then a newline character, a tab character, a percent character,
173 or the current file number is printed, otherwise the string is
174 examined for the following:
176 Any of the following optional flags:
177 .Bl -tag -width indent
179 Selects an alternate output form for octal and hexadecimal output.
180 Non-zero octal output will have a leading zero, and non-zero
181 hexadecimal output will have
185 Asserts that a sign indicating whether a number is positive or negative
186 should always be printed.
187 Non-negative numbers are not usually printed
190 Aligns string output to the left of the field, instead of to the right.
192 Sets the fill character for left padding to the
194 character, instead of a space.
196 Reserves a space at the front of non-negative signed output fields.
199 overrides a space if both are used.
202 Then the following fields:
203 .Bl -tag -width indent
205 An optional decimal digit string specifying the minimum field width.
207 An optional precision composed of a decimal point
209 and a decimal digit string that indicates the maximum string length,
210 the number of digits to appear after the decimal point in floating point
211 output, or the minimum number of digits to appear in numeric output.
213 An optional output format specifier which is one of
214 .Cm D , O , U , X , F ,
217 These represent signed decimal output, octal output, unsigned decimal
218 output, hexadecimal output, floating point output, and string output,
220 Some output formats do not apply to all fields.
221 Floating point output only applies to
229 The special output specifier
231 may be used to indicate that the output, if
232 applicable, should be in string format.
233 May be used in combination with:
234 .Bl -tag -width indent
240 Display actual device name.
242 Display group or user name.
258 Note that the default output format
261 is a string, but if specified explicitly, these four characters are
265 An optional sub field specifier (high, middle, low).
272 It can be one of the following:
273 .Bl -tag -width indent
277 specifies the major number for devices from
283 bits for permissions from the string form of
287 bits from the numeric forms of
289 and the long output form of
294 specifies the minor number for devices from
300 bits for permissions from the string form of
307 bits from the numeric forms of
311 style output character for file type when used with
315 for this is optional).
321 bits for permissions from the
322 string output form of
329 bits for the numeric forms of
333 A required field specifier, being one of the following:
334 .Bl -tag -width indent
343 File type and permissions.
345 Number of hard links to
348 User ID and group ID of
352 Device number for character and block device special files.
356 was last accessed or modified, or when the inode was last changed, or
357 the birth time of the inode.
363 Number of blocks allocated for
366 Optimal file system I/O operation block size.
368 User defined flags for
371 Inode generation number.
374 The following four field specifiers are not drawn directly from the
378 .Bl -tag -width indent
380 The name of the file.
382 The file type, either as in
384 or in a more descriptive form if the
390 The target of a symbolic link.
396 field for character or block
397 special devices and gives size output for all others.
403 and the field specifier are required.
404 Most field specifiers default to
406 as an output form, with the
423 .Ex -std stat readlink
425 Given a symbolic link
434 .Bd -literal -offset indent
435 \*[Gt] stat -F /tmp/foo
436 lrwxrwxrwx 1 jschauma cs 1 Apr 24 16:37:28 2002 /tmp/foo@ -\*[Gt] /
438 \*[Gt] stat -LF /tmp/foo
439 drwxr-xr-x 16 root wheel 512 Apr 19 10:57:54 2002 /tmp/foo/
442 To initialize some shell variables, you could use the
445 .Bd -literal -offset indent
447 % eval set `stat -s .cshrc`
448 % echo $st_size $st_mtimespec
452 $ eval $(stat -s .profile)
453 $ echo $st_size $st_mtimespec
457 In order to get a list of the kind of files including files pointed to if the
458 file is a symbolic link, you could use the following format:
459 .Bd -literal -offset indent
460 $ stat -f "%N: %HT%SY" /tmp/*
461 /tmp/bar: Symbolic Link -\*[Gt] /tmp/foo
462 /tmp/output25568: Regular File
464 /tmp/foo: Symbolic Link -\*[Gt] /
467 In order to get a list of the devices, their types and the major and minor
468 device numbers, formatted with tabs and linebreaks, you could use the
470 .Bd -literal -offset indent
471 stat -f "Name: %N%n%tType: %HT%n%tMajor: %Hr%n%tMinor: %Lr%n%n" /dev/*
474 Type: Character Device
479 Type: Character Device
484 In order to determine the permissions set on a file separately, you could use
485 the following format:
486 .Bd -literal -offset indent
487 \*[Gt] stat -f "%Sp -\*[Gt] owner=%SHp group=%SMp other=%SLp" .
488 drwxr-xr-x -\*[Gt] owner=rwx group=r-x other=r-x
491 In order to determine the three files that have been modified most recently,
492 you could use the following format:
493 .Bd -literal -offset indent
494 \*[Gt] stat -f "%m%t%Sm %N" /tmp/* | sort -rn | head -3 | cut -f2-
495 Apr 25 11:47:00 2002 /tmp/blah
496 Apr 25 10:36:34 2002 /tmp/bar
497 Apr 24 16:47:35 2002 /tmp/foo
518 utility was written by
520 .Aq atatat@NetBSD.org .
521 This man page was written by
523 .Aq jschauma@NetBSD.org .