1 .\" $NetBSD: stat.1,v 1.28 2010/04/05 21:25:01 joerg 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
102 fields, in that order.
104 The options are as follows:
105 .Bl -tag -width XFXformatXXX
111 immediately after each pathname that is a directory, an
114 after each that is executable, an at sign
116 after each symbolic link, a percent sign
118 after each whiteout, an equal sign
120 after each socket, and a vertical bar
122 after each that is a FIFO.
128 Display information using the specified format.
131 section for a description of valid formats.
137 The information reported by
139 will refer to the target of
141 if file is a symbolic link, and not to
149 Do not force a newline to appear at the end of each piece of output.
151 Suppress failure messages if calls to
158 error messages are automatically suppressed.
160 Display raw information.
161 That is, for all the fields in the stat-structure,
162 display the raw, numerical value (for example, times in seconds since the
165 Display information in
167 suitable for initializing variables.
169 Display timestamps using the specified format.
174 Display information in a more verbose way as known from some Linux
178 Format strings are similar to
180 formats in that they start with
182 are then followed by a sequence of formatting characters, and end in
183 a character that selects the field of the struct stat which is to be
187 is immediately followed by one of
193 then a newline character, a tab character, a percent character,
194 or the current file number is printed, otherwise the string is
195 examined for the following:
197 Any of the following optional flags:
200 Selects an alternate output form for octal and hexadecimal output.
201 Non-zero octal output will have a leading zero, and non-zero
202 hexadecimal output will have
206 Asserts that a sign indicating whether a number is positive or negative
207 should always be printed.
208 Non-negative numbers are not usually printed with a sign.
210 Aligns string output to the left of the field, instead of to the right.
212 Sets the fill character for left padding to the 0 character, instead of
215 Reserves a space at the front of non-negative signed output fields.
218 overrides a space if both are used.
221 Then the following fields:
224 An optional decimal digit string specifying the minimum field width.
226 An optional precision composed of a decimal point
228 and a decimal digit string that indicates the maximum string length,
229 the number of digits to appear after the decimal point in floating point
230 output, or the minimum number of digits to appear in numeric output.
232 An optional output format specifier which is one of
240 These represent signed decimal output, octal output, unsigned decimal
241 output, hexadecimal output, floating point output, and string output,
243 Some output formats do not apply to all fields.
244 Floating point output only applies to timespec fields (the
251 The special output specifier
253 may be used to indicate that the output, if
254 applicable, should be in string format.
255 May be used in combination with
258 Display date in strftime(3) format.
260 Display actual device name.
262 Display group or user name.
275 Insert a `` -\*[Gt] '' into the output.
276 Note that the default output format for
278 is a string, but if specified explicitly, these four characters are
282 An optional sub field specifier (high, middle, or low).
292 It can be one of the following:
298 .Bl -tag -compact -width door
300 Major number for devices
303 bits from the string form of permissions or the file
305 bits from the numeric forms
307 The long output form of file type
309 Directory path of the file, similar to what
313 File size, rounded to the nearest gigabyte
319 .Bl -tag -compact -width door
323 bits from the string form of permissions or the
328 bits from the numeric forms
330 File size, rounded to the nearest megabyte
336 .Bl -tag -compact -width door
338 Minor number for devices
342 bits from the string form of permissions or the
347 bits from the numeric forms
351 style output character for file type (the use of
355 Base filename of the file, similar to what
359 File size, rounded to the nearest kilobyte
363 A required field specifier, being one of the following:
375 File type and permissions
378 Number of hard links to
382 User-id and group-id of
385 .Pq Fa st_uid , st_gid .
387 Device number for character and block device special files
392 was last accessed or modified, or when the inode was last changed, or
393 the birth time of the inode
394 .Pq Fa st_atime , st_mtime , st_ctime, st_birthtime .
401 Number of blocks allocated for
405 Optimal file system I/O operation block size
408 User defined flags for
412 Inode generation number
416 The following five field specifiers are not drawn directly from the
417 data in struct stat, but are:
420 The name of the file.
422 The absolute pathname corresponding to the file.
424 The file type, either as in
426 or in a more descriptive form if the sub field specifier
430 The target of a symbolic link.
434 from the rdev field for character or block
435 special devices and gives size output for all others.
441 and the field specifier are required.
442 Most field specifiers default to
444 as an output form, with the
462 exits 0 on success, and \*[Gt]0 if an error occurred.
464 If no options are specified, the default format is
465 "%d %i %Sp %l %Su %Sg %r %z \e"%Sa\e" \e"%Sm\e" \e"%Sc\e" \e"%SB\e" %k %b %#Xf %N".
466 .Bd -literal -offset indent
468 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
471 Given a symbolic link
480 .Bd -literal -offset indent
481 \*[Gt] stat -F /tmp/foo
482 lrwxrwxrwx 1 jschauma cs 1 Apr 24 16:37:28 2002 /tmp/foo@ -\*[Gt] /
484 \*[Gt] stat -LF /tmp/foo
485 drwxr-xr-x 16 root wheel 512 Apr 19 10:57:54 2002 /tmp/foo/
488 To initialize some shell-variables, you could use the
491 .Bd -literal -offset indent
493 % eval set `stat -s .cshrc`
494 % echo $st_size $st_mtime
498 $ eval $(stat -s .profile)
499 $ echo $st_size $st_mtime
503 In order to get a list of the kind of files including files pointed to if the
504 file is a symbolic link, you could use the following format:
505 .Bd -literal -offset indent
506 $ stat -f "%N: %HT%SY" /tmp/*
507 /tmp/bar: Symbolic Link -\*[Gt] /tmp/foo
508 /tmp/output25568: Regular File
510 /tmp/foo: Symbolic Link -\*[Gt] /
513 In order to get a list of the devices, their types and the major and minor
514 device numbers, formatted with tabs and linebreaks, you could use the
516 .Bd -literal -offset indent
517 stat -f "Name: %N%n%tType: %HT%n%tMajor: %Hr%n%tMinor: %Lr%n%n" /dev/*
525 Type: Character Device
530 In order to determine the permissions set on a file separately, you could use
531 the following format:
532 .Bd -literal -offset indent
533 \*[Gt] stat -f "%Sp -\*[Gt] owner=%SHp group=%SMp other=%SLp" .
534 drwxr-xr-x -\*[Gt] owner=rwx group=r-x other=r-x
537 In order to determine the three files that have been modified most recently,
538 you could use the following format:
539 .Bd -literal -offset indent
540 \*[Gt] stat -f "%m%t%Sm %N" /tmp/* | sort -rn | head -3 | cut -f2-
541 Apr 25 11:47:00 2002 /tmp/blah
542 Apr 25 10:36:34 2002 /tmp/bar
543 Apr 24 16:47:35 2002 /tmp/foo
564 utility was written by
566 .Aq atatat@NetBSD.org .
567 This man page was written by
569 .Aq jschauma@NetBSD.org .