1 .\" $NetBSD: stat.1,v 1.36 2012/12/03 07:49:21 wiz Exp $
3 .\" Copyright (c) 2002-2011 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.
170 suppress error messages.
171 This is equivalent to specifying
173 FMT="st_dev=%d st_ino=%i st_mode=%#p st_nlink=%l st_uid=%u st_gid=%g"
174 FMT="$FMT st_rdev=%r st_size=%z st_atime=%Sa st_mtime=%Sm st_ctime=%Sc"
175 FMT="$FMT st_birthtime=%SB st_blksize=%k st_blocks=%b st_flags=%f"
176 stat -t %s -f "$FMT" .
178 Note that if you use a timeformat that contains embedded whitespace or shell
179 meta-characters you will need to include appropriate quoting so the
181 output remains valid.
183 Display timestamps using the specified format.
190 Display information in a more verbose way as known from some Linux
194 Format strings are similar to
196 formats in that they start with
198 are then followed by a sequence of formatting characters, and end in
199 a character that selects the field of the struct stat which is to be
203 is immediately followed by one of
209 then a newline character, a tab character, a percent character,
210 or the current file number is printed, otherwise the string is
211 examined for the following:
213 Any of the following optional flags:
216 Selects an alternate output form for string, octal and hexadecimal output.
217 String output will be encoded in
220 Non-zero octal output will have a leading zero.
221 Non-zero hexadecimal output will have
225 Asserts that a sign indicating whether a number is positive or negative
226 should always be printed.
227 Non-negative numbers are not usually printed with a sign.
229 Aligns string output to the left of the field, instead of to the right.
231 Sets the fill character for left padding to the 0 character, instead of
234 Reserves a space at the front of non-negative signed output fields.
237 overrides a space if both are used.
240 Then the following fields:
243 An optional decimal digit string specifying the minimum field width.
245 An optional precision composed of a decimal point
247 and a decimal digit string that indicates the maximum string length,
248 the number of digits to appear after the decimal point in floating point
249 output, or the minimum number of digits to appear in numeric output.
251 An optional output format specifier which is one of
259 These represent signed decimal output, octal output, unsigned decimal
260 output, hexadecimal output, floating point output, and string output,
262 Some output formats do not apply to all fields.
263 Floating point output only applies to timespec fields (the
270 The special output specifier
272 may be used to indicate that the output, if
273 applicable, should be in string format.
274 May be used in combination with
277 Display date in strftime(3) format.
279 Display actual device name.
281 Display group or user name.
294 Insert a `` -\*[Gt] '' into the output.
295 Note that the default output format for
297 is a string, but if specified explicitly, these four characters are
301 An optional sub field specifier (high, middle, or low).
311 It can be one of the following:
317 .Bl -tag -compact -width door
319 Major number for devices
322 bits from the string form of permissions or the file
324 bits from the numeric forms
326 The long output form of file type
328 Directory path of the file, similar to what
332 File size, rounded to the nearest gigabyte
338 .Bl -tag -compact -width door
342 bits from the string form of permissions or the
347 bits from the numeric forms
349 File size, rounded to the nearest megabyte
355 .Bl -tag -compact -width door
357 Minor number for devices
361 bits from the string form of permissions or the
366 bits from the numeric forms
370 style output character for file type (the use of
374 Base filename of the file, similar to what
378 File size, rounded to the nearest kilobyte
382 A required field specifier, being one of the following:
394 File type and permissions
397 Number of hard links to
401 User-id and group-id of
404 .Pq Fa st_uid , st_gid .
406 Device number for character and block device special files
411 was last accessed or modified, or when the inode was last changed, or
412 the birth time of the inode
413 .Pq Fa st_atime , st_mtime , st_ctime, st_birthtime .
420 Number of blocks allocated for
424 Optimal file system I/O operation block size
427 User defined flags for
431 Inode generation number
435 The following five field specifiers are not drawn directly from the
436 data in struct stat, but are:
439 The name of the file.
441 The absolute pathname corresponding to the file.
443 The file type, either as in
445 or in a more descriptive form if the sub field specifier
449 The target of a symbolic link.
452 .Dq Ar major , Ns Ar minor
453 from the rdev field for character or block
454 special devices and gives size output for all others.
460 and the field specifier are required.
461 Most field specifiers default to
463 as an output form, with the
481 exits 0 on success, and \*[Gt]0 if an error occurred.
483 If no options are specified, the default format is
484 "%d %i %Sp %l %Su %Sg %r %z \e"%Sa\e" \e"%Sm\e" \e"%Sc\e" \e"%SB\e" %k %b %#Xf %N".
485 .Bd -literal -offset indent
487 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
490 This example produces output very similar to that from
494 displays the time in a different format, and
496 sometimes adds one or more spaces after the comma in
497 .Dq Ar major , Ns Ar minor
499 .Bd -literal -offset indent
500 \*[Gt] stat -f "%7i %6b %-11Sp %3l %-17Su %-17Sg %9Z %Sm %N%SY" /tmp/bar
501 78852 0 -rw-r--r-- 1 root wheel 0 Jul 8 10:26:03 2004 /tmp/bar
503 \*[Gt] find /tmp/bar -ls -exit
504 78852 0 -rw-r--r-- 1 root wheel 0 Jul 8 2004 /tmp/bar
507 This example produces output very similar to that from
511 adjusts the column spacing differently when listing multiple files,
514 adds at least one space after the comma in
515 .Dq Ar major , Ns Ar minor
517 .Bd -literal -offset indent
518 \*[Gt] stat -f "%-11Sp %l %Su %Sg %Z %Sm %N%SY" /tmp/bar
519 -rw-r--r-- 1 root wheel 0 Jul 8 10:26:03 2004 /tmp/bar
521 \*[Gt] ls -lTd /tmp/bar
522 -rw-r--r-- 1 root wheel 0 Jul 8 10:26:03 2004 /tmp/bar
525 Given a symbolic link
534 .Bd -literal -offset indent
535 \*[Gt] stat -F /tmp/foo
536 lrwxrwxrwx 1 jschauma cs 1 Apr 24 16:37:28 2002 /tmp/foo@ -\*[Gt] /
538 \*[Gt] stat -LF /tmp/foo
539 drwxr-xr-x 16 root wheel 512 Apr 19 10:57:54 2002 /tmp/foo/
542 To initialize some shell-variables, you could use the
545 .Bd -literal -offset indent
547 % eval set `stat -s .cshrc`
548 % echo $st_size $st_mtime
552 $ eval $(stat -s .profile)
553 $ echo $st_size $st_mtime
557 In order to get a list of the kind of files including files pointed to if the
558 file is a symbolic link, you could use the following format:
559 .Bd -literal -offset indent
560 $ stat -f "%N: %HT%SY" /tmp/*
561 /tmp/bar: Symbolic Link -\*[Gt] /tmp/foo
562 /tmp/output25568: Regular File
564 /tmp/foo: Symbolic Link -\*[Gt] /
567 In order to get a list of the devices, their types and the major and minor
568 device numbers, formatted with tabs and linebreaks, you could use the
570 .Bd -literal -offset indent
571 stat -f "Name: %N%n%tType: %HT%n%tMajor: %Hr%n%tMinor: %Lr%n%n" /dev/*
579 Type: Character Device
584 In order to determine the permissions set on a file separately, you could use
585 the following format:
586 .Bd -literal -offset indent
587 \*[Gt] stat -f "%Sp -\*[Gt] owner=%SHp group=%SMp other=%SLp" .
588 drwxr-xr-x -\*[Gt] owner=rwx group=r-x other=r-x
591 In order to determine the three files that have been modified most recently,
592 you could use the following format:
593 .Bd -literal -offset indent
594 \*[Gt] stat -f "%m%t%Sm %N" /tmp/* | sort -rn | head -3 | cut -f2-
595 Apr 25 11:47:00 2002 /tmp/blah
596 Apr 25 10:36:34 2002 /tmp/bar
597 Apr 24 16:47:35 2002 /tmp/foo
600 User names, group names, and file names that contain spaces
601 or other special characters may be encoded in
606 .Bd -literal -offset indent
607 \*[Gt] ln -s 'target with spaces' 'link with spaces'
608 \*[Gt] stat -f "%#N%#SY" 'link with spaces'
609 link\eswith\esspaces -\*[Gt] target\eswith\esspaces
630 utility was written by
632 .Aq atatat@NetBSD.org .
633 This man page was written by
635 .Aq jschauma@NetBSD.org .