1 .\" $NetBSD: stat.1,v 1.25 2008/11/07 15:33:31 reed Exp $
3 .\" Copyright (c) 2002-2005 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.
168 Display timestamps using the specified format.
173 Display information in a more verbose way as known from some Linux
177 Format strings are similar to
179 formats in that they start with
181 are then followed by a sequence of formatting characters, and end in
182 a character that selects the field of the struct stat which is to be
186 is immediately followed by one of
192 then a newline character, a tab character, a percent character,
193 or the current file number is printed, otherwise the string is
194 examined for the following:
196 Any of the following optional flags:
199 Selects an alternate output form for octal and hexadecimal output.
200 Non-zero octal output will have a leading zero, and non-zero
201 hexadecimal output will have
205 Asserts that a sign indicating whether a number is positive or negative
206 should always be printed.
207 Non-negative numbers are not usually printed with a sign.
209 Aligns string output to the left of the field, instead of to the right.
211 Sets the fill character for left padding to the 0 character, instead of
214 Reserves a space at the front of non-negative signed output fields.
217 overrides a space if both are used.
220 Then the following fields:
223 An optional decimal digit string specifying the minimum field width.
225 An optional precision composed of a decimal point
227 and a decimal digit string that indicates the maximum string length,
228 the number of digits to appear after the decimal point in floating point
229 output, or the minimum number of digits to appear in numeric output.
231 An optional output format specifier which is one of
239 These represent signed decimal output, octal output, unsigned decimal
240 output, hexadecimal output, floating point output, and string output,
242 Some output formats do not apply to all fields.
243 Floating point output only applies to timespec fields (the
250 The special output specifier
252 may be used to indicate that the output, if
253 applicable, should be in string format.
254 May be used in combination with
257 Display date in strftime(3) format.
259 Display actual device name.
261 Display group or user name.
274 Insert a `` -\*[Gt] '' into the output.
275 Note that the default output format for
277 is a string, but if specified explicitly, these four characters are
281 An optional sub field specifier (high, middle, or low).
291 It can be one of the following:
297 .Bl -tag -compact -width door
299 Major number for devices
302 bits from the string form of permissions or the file
304 bits from the numeric forms
306 The long output form of file type
308 Directory path of the file, similar to what
312 File size, rounded to the nearest gigabyte
318 .Bl -tag -compact -width door
322 bits from the string form of permissions or the
327 bits from the numeric forms
329 File size, rounded to the nearest megabyte
335 .Bl -tag -compact -width door
337 Minor number for devices
341 bits from the string form of permissions or the
346 bits from the numeric forms
350 style output character for file type (the use of
354 Base filename of the file, similar to what
358 File size, rounded to the nearest kilobyte
362 A required field specifier, being one of the following:
374 File type and permissions
377 Number of hard links to
381 User-id and group-id of
384 .Pq Fa st_uid , st_gid .
386 Device number for character and block device special files
391 was last accessed or modified, or when the inode was last changed, or
392 the birth time of the inode
393 .Pq Fa st_atime , st_mtime , st_ctime, st_birthtime .
400 Number of blocks allocated for
404 Optimal file system I/O operation block size
407 User defined flags for
411 Inode generation number
415 The following five field specifiers are not drawn directly from the
416 data in struct stat, but are:
419 The name of the file.
421 The absolute pathname corresponding to the file.
423 The file type, either as in
425 or in a more descriptive form if the sub field specifier
429 The target of a symbolic link.
433 from the rdev field for character or block
434 special devices and gives size output for all others.
440 and the field specifier are required.
441 Most field specifiers default to
443 as an output form, with the
461 exits 0 on success, and \*[Gt]0 if an error occurred.
463 If no options are specified, the default format is
464 "%d %i %Sp %l %Su %Sg %r %z \\"%Sa\\" \\"%Sm\\" \\"%Sc\\" \\"%SB\\" %k %b %#Xf %N".
465 .Bd -literal -offset indent
467 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
470 Given a symbolic link
479 .Bd -literal -offset indent
480 \*[Gt] stat -F /tmp/foo
481 lrwxrwxrwx 1 jschauma cs 1 Apr 24 16:37:28 2002 /tmp/foo@ -\*[Gt] /
483 \*[Gt] stat -LF /tmp/foo
484 drwxr-xr-x 16 root wheel 512 Apr 19 10:57:54 2002 /tmp/foo/
487 To initialize some shell-variables, you could use the
490 .Bd -literal -offset indent
492 % eval set `stat -s .cshrc`
493 % echo $st_size $st_mtime
497 $ eval $(stat -s .profile)
498 $ echo $st_size $st_mtime
502 In order to get a list of the kind of files including files pointed to if the
503 file is a symbolic link, you could use the following format:
504 .Bd -literal -offset indent
505 $ stat -f "%N: %HT%SY" /tmp/*
506 /tmp/bar: Symbolic Link -\*[Gt] /tmp/foo
507 /tmp/output25568: Regular File
509 /tmp/foo: Symbolic Link -\*[Gt] /
512 In order to get a list of the devices, their types and the major and minor
513 device numbers, formatted with tabs and linebreaks, you could use the
515 .Bd -literal -offset indent
516 stat -f "Name: %N%n%tType: %HT%n%tMajor: %Hr%n%tMinor: %Lr%n%n" /dev/*
524 Type: Character Device
529 In order to determine the permissions set on a file separately, you could use
530 the following format:
531 .Bd -literal -offset indent
532 \*[Gt] stat -f "%Sp -\*[Gt] owner=%SHp group=%SMp other=%SLp" .
533 drwxr-xr-x -\*[Gt] owner=rwx group=r-x other=r-x
536 In order to determine the three files that have been modified most recently,
537 you could use the following format:
538 .Bd -literal -offset indent
539 \*[Gt] stat -f "%m%t%Sm %N" /tmp/* | sort -rn | head -3 | cut -f2-
540 Apr 25 11:47:00 2002 /tmp/blah
541 Apr 25 10:36:34 2002 /tmp/bar
542 Apr 24 16:47:35 2002 /tmp/foo
563 utility was written by
565 .Aq atatat@NetBSD.org .
566 This man page was written by
568 .Aq jschauma@NetBSD.org .