xref: /netbsd-src/usr.bin/stat/stat.1 (revision ed7b026d6f53504a6c721476a46bc225a41491df)
1*ed7b026dSchristos.\"	$NetBSD: stat.1,v 1.47 2024/01/29 21:55:24 christos Exp $
2ba4e8c96Satatat.\"
364d2b8e0Sapb.\" Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
4ba4e8c96Satatat.\" All rights reserved.
5ba4e8c96Satatat.\"
6ba4e8c96Satatat.\" This code is derived from software contributed to The NetBSD Foundation
7ba4e8c96Satatat.\" by Andrew Brown and Jan Schaumann.
8ba4e8c96Satatat.\"
9ba4e8c96Satatat.\" Redistribution and use in source and binary forms, with or without
10ba4e8c96Satatat.\" modification, are permitted provided that the following conditions
11ba4e8c96Satatat.\" are met:
12ba4e8c96Satatat.\" 1. Redistributions of source code must retain the above copyright
13ba4e8c96Satatat.\"    notice, this list of conditions and the following disclaimer.
14ba4e8c96Satatat.\" 2. Redistributions in binary form must reproduce the above copyright
15ba4e8c96Satatat.\"    notice, this list of conditions and the following disclaimer in the
16ba4e8c96Satatat.\"    documentation and/or other materials provided with the distribution.
17ba4e8c96Satatat.\"
18ba4e8c96Satatat.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19ba4e8c96Satatat.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20ba4e8c96Satatat.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21ba4e8c96Satatat.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22ba4e8c96Satatat.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23ba4e8c96Satatat.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24ba4e8c96Satatat.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25ba4e8c96Satatat.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26ba4e8c96Satatat.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27ba4e8c96Satatat.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28ba4e8c96Satatat.\" POSSIBILITY OF SUCH DAMAGE.
29ba4e8c96Satatat.\"
30*ed7b026dSchristos.Dd January 29, 2023
31b1017b64Swiz.Dt STAT 1
32ba4e8c96Satatat.Os
33ba4e8c96Satatat.Sh NAME
3414ef4b89Skre.Nm stat
35ba4e8c96Satatat.Nd display file status
36ba4e8c96Satatat.Sh SYNOPSIS
37b1017b64Swiz.Nm
3895c295f3Satatat.Op Fl FLnq
39ba4e8c96Satatat.Oo
40ba4e8c96Satatat.Fl f Ar format |
41ba4e8c96Satatat.Fl l |
42ba4e8c96Satatat.Fl r |
43ba4e8c96Satatat.Fl s |
44ba4e8c96Satatat.Fl x
45ba4e8c96Satatat.Oc
46ba4e8c96Satatat.Op Fl t Ar timefmt
47ba4e8c96Satatat.Op Ar
48ba4e8c96Satatat.Sh DESCRIPTION
49ba4e8c96SatatatThe
50ba4e8c96Satatat.Nm
5114ef4b89Skreutility displays information about each file given by
52ba4e8c96Satatat.Ar file .
5314ef4b89SkreRead, write, or execute permissions for the named file are not required, but
54ba4e8c96Satatatall directories listed in the pathname leading to the file must be
55be8ae688Sgrantsearchable.
5614ef4b89Skre.Pp
5714ef4b89SkreIf no
5814ef4b89Skre.Ar file
5914ef4b89Skreargument is given,
60ba4e8c96Satatat.Nm
61ba4e8c96Satatatdisplays information about the file descriptor for standard input.
6214ef4b89SkreIn this case the
6314ef4b89Skre.Fl L
6414ef4b89Skreoption is ignored, and
6514ef4b89Skre.Nm
6614ef4b89Skreuses
6714ef4b89Skre.Xr fstat 2
6814ef4b89Skrerather than
69b1017b64Swiz.Xr lstat 2
7014ef4b89Skreor
7114ef4b89Skre.Xr stat 2
7214ef4b89Skreto obtain information.
7314ef4b89SkreThe
7414ef4b89Skre.Sq file name
7514ef4b89Skre(and also the
7614ef4b89Skre.Sq path name )
7714ef4b89Skrein this case is
78fc5c743eSuwe.Ql \&(stdin) .
795996912dSkreThe file number
80fc5c743eSuwe.Pq Ql %@
815996912dSkrewill be zero.
8214ef4b89Skre.Pp
8314ef4b89SkreOtherwise the information displayed is obtained by calling
8414ef4b89Skre.Xr lstat 2
8514ef4b89Skre(or
8614ef4b89Skre.Xr stat 2
8714ef4b89Skrewith
8814ef4b89Skre.Fl L )
8914ef4b89Skrewith each given argument in turn and evaluating the returned structure.
9014ef4b89Skre.Pp
91ed200f58SwizThe default format displays the
92ed200f58Swiz.Fa st_dev ,
93ed200f58Swiz.Fa st_ino ,
94ed200f58Swiz.Fa st_mode ,
95ed200f58Swiz.Fa st_nlink ,
96ed200f58Swiz.Fa st_uid ,
97ed200f58Swiz.Fa st_gid ,
98ed200f58Swiz.Fa st_rdev ,
99ed200f58Swiz.Fa st_size ,
100ed200f58Swiz.Fa st_atime ,
101ed200f58Swiz.Fa st_mtime ,
102ed200f58Swiz.Fa st_ctime ,
103fc5eb1b7Senami.Fa st_birthtime ,
104ed200f58Swiz.Fa st_blksize ,
105ed200f58Swiz.Fa st_blocks ,
106ed200f58Swizand
107ed200f58Swiz.Fa st_flags
108ed200f58Swizfields, in that order.
109ba4e8c96Satatat.Pp
110ba4e8c96SatatatThe options are as follows:
111fc5c743eSuwe.Bl -tag -width Fl
112ba4e8c96Satatat.It Fl F
113ba4e8c96SatatatAs in
1143c0fa0f0Swiz.Xr ls 1 ,
115d05a0420Swizdisplay a slash
116fc5c743eSuwe.Pq Ql /
117d05a0420Swizimmediately after each pathname that is a directory, an
118d05a0420Swizasterisk
119fc5c743eSuwe.Pq Ql *
120d05a0420Swizafter each that is executable, an at sign
121fc5c743eSuwe.Pq Ql @
122d05a0420Swizafter each symbolic link, a percent sign
123fc5c743eSuwe.Pq Ql %
124d05a0420Swizafter each whiteout, an equal sign
125fc5c743eSuwe.Pq Ql =
126d05a0420Swizafter each socket, and a vertical bar
127fc5c743eSuwe.Pq Ql \&|
128d05a0420Swizafter each that is a FIFO.
129be8ae688SgrantThe use of
130ba4e8c96Satatat.Fl F
131ba4e8c96Satatatimplies
132ba4e8c96Satatat.Fl l .
133d05a0420Swiz.It Fl f Ar format
134d05a0420SwizDisplay information using the specified format.
135d05a0420SwizSee the
136d05a0420Swiz.Sx FORMATS
137d05a0420Swizsection for a description of valid formats.
138ba4e8c96Satatat.It Fl L
139ba4e8c96SatatatUse
140ba4e8c96Satatat.Xr stat 2
141ba4e8c96Satatatinstead of
142ba4e8c96Satatat.Xr lstat 2 .
143b1017b64SwizThe information reported by
144ba4e8c96Satatat.Nm
145ba4e8c96Satatatwill refer to the target of
146ba4e8c96Satatat.Ar file ,
14714ef4b89Skreif
14814ef4b89Skre.Ar file
14914ef4b89Skreis a symbolic link, rather than to
150ba4e8c96Satatat.Ar file
151ba4e8c96Satatatitself.
152d05a0420Swiz.It Fl l
153d05a0420SwizDisplay output in
154d05a0420Swiz.Ic ls Fl lT
155d05a0420Swizformat.
156ba4e8c96Satatat.It Fl n
157ba4e8c96SatatatDo not force a newline to appear at the end of each piece of output.
15895c295f3Satatat.It Fl q
15995c295f3SatatatSuppress failure messages if calls to
16014ef4b89Skre.Xr fstat 2 ,
16114ef4b89Skre.Xr lstat 2 ,
16214ef4b89Skre.Xr readlink 2 ,
16314ef4b89Skre.Xr realpath 3 ,
16495c295f3Satatator
16514ef4b89Skre.Xr stat 2
166be8ae688Sgrantfail.
167ba4e8c96Satatat.It Fl r
168be8ae688SgrantDisplay raw information.
169be8ae688SgrantThat is, for all the fields in the stat-structure,
170ba4e8c96Satatatdisplay the raw, numerical value (for example, times in seconds since the
171ba4e8c96Satatatepoch, etc.)
172ba4e8c96Satatat.It Fl s
173d05a0420SwizDisplay information in
17414ef4b89Skre.Dq shell command
17514ef4b89Skreoutput format,
176d05a0420Swizsuitable for initializing variables.
177740a1241SerhThis is equivalent to specifying
178740a1241Serh.Bd -literal
17914ef4b89SkreFMT="st_dev=%d st_ino=%i st_mode=%#p st_nlink=%l"
18014ef4b89SkreFMT="$FMT st_uid=%u st_gid=%g st_rdev=%r st_size=%z"
18114ef4b89SkreFMT="$FMT st_atime=%Sa st_mtime=%Sm st_ctime=%Sc"
18214ef4b89SkreFMT="$FMT st_birthtime=%SB st_blksize=%k st_blocks=%b"
18314ef4b89SkreFMT="$FMT st_flags=%f"
184740a1241Serhstat -t %s -f "$FMT" .
185740a1241Serh.Ed
18614ef4b89Skre.Pp
187fc5c743eSuweThe
188fc5c743eSuwe.Ar timefmt
189fc5c743eSuwemay be altered from the default for
190740a1241Serh.Fl s
191fc5c743eSuwe.Pq Ql \&%s
19214ef4b89Skreby also using the
19314ef4b89Skre.Fl t
19414ef4b89Skreoption.
195fc5c743eSuweNote that if you use a
196fc5c743eSuwe.Ar timefmt
197fc5c743eSuwethat contains embedded whitespace or shell
198ba4e23c9Skremeta-characters,
19914ef4b89Skreyou will need to
20014ef4b89Skreinclude appropriate quoting in the
20114ef4b89Skre.Fl t
20214ef4b89Skreformat, or supply an explicit format
20314ef4b89Skre.Pq Fl f ,
20414ef4b89Skrerather than
20514ef4b89Skre.Fl s ,
20614ef4b89Skrewith the format containing appropriate quoting so the output remains valid.
207ba4e8c96Satatat.It Fl t Ar timefmt
20814ef4b89SkreDisplay timestamps, when to be output in string format,
20914ef4b89Skreusing the specified format.
210be8ae688SgrantThis format is
211ba4e8c96Satatatpassed directly to
212952c61b2Schristos.Xr strftime 3
213fc5c743eSuwewith the extension that
214fc5c743eSuwe.Ql %f
215fc5c743eSuweprints nanoseconds if available.
216d05a0420Swiz.It Fl x
21714ef4b89SkreDisplay information in a more verbose way as seen from some Linux
218d05a0420Swizdistributions.
219ba4e8c96Satatat.El
220b1017b64Swiz.Ss FORMATS
221ba4e8c96SatatatFormat strings are similar to
222ba4e8c96Satatat.Xr printf 3
22314ef4b89Skreformats in that they contain character data,
22414ef4b89Skrewhich is simply output,
22514ef4b89Skreinterspersed with data conversions which start with
226ba4e8c96Satatat.Cm % ,
227ba4e8c96Satatatare then followed by a sequence of formatting characters, and end in
22814ef4b89Skrea character that selects the datum, the field of the struct stat,
22914ef4b89Skreor other data,
23014ef4b89Skrewhich is to be formatted.
231be8ae688SgrantIf the
232ba4e8c96Satatat.Cm %
233ba4e8c96Satatatis immediately followed by one of
234ba4e8c96Satatat.Cm n ,
235ba4e8c96Satatat.Cm t ,
236ba4e8c96Satatat.Cm % ,
23704712927Satatator
23804712927Satatat.Cm @ ,
23904712927Satatatthen a newline character, a tab character, a percent character,
24014ef4b89Skreor the current file number in the argument list is printed.
24114ef4b89SkreOtherwise the string is examined for the following:
242ba4e8c96Satatat.Pp
24314ef4b89SkreAny of the following optional flags in any order:
244fc5c743eSuwe.Bl -tag -width Cm
245ba4e8c96Satatat.It Cm #
24664d2b8e0SapbSelects an alternate output form for string, octal and hexadecimal output.
24764d2b8e0SapbString output will be encoded in
24864d2b8e0Sapb.Xr vis 3
24964d2b8e0Sapbstyle.
25014ef4b89SkreOctal output will have a leading zero.
25164d2b8e0SapbNon-zero hexadecimal output will have
252fc5c743eSuwe.Ql 0x
253d05a0420Swizprepended to it.
254ba4e8c96Satatat.It Cm +
255ba4e8c96SatatatAsserts that a sign indicating whether a number is positive or negative
256be8ae688Sgrantshould always be printed.
257d05a0420SwizNon-negative numbers are not usually printed with a sign.
258ba4e8c96Satatat.It Cm -
259ba4e8c96SatatatAligns string output to the left of the field, instead of to the right.
260ba4e8c96Satatat.It Cm 0
261ba4e8c96SatatatSets the fill character for left padding to the 0 character, instead of
262ba4e8c96Satatata space.
263ba4e8c96Satatat.It space
264be8ae688SgrantReserves a space at the front of non-negative signed output fields.
265be8ae688SgrantA
266ba4e8c96Satatat.Sq Cm +
267ba4e8c96Satatatoverrides a space if both are used.
268ba4e8c96Satatat.El
269ba4e8c96Satatat.Pp
27014ef4b89SkreThen followed by the following fields in the following order:
271fc5c743eSuwe.Bl -tag -width Ar
272fc5c743eSuwe.It Ar size
273ba4e8c96SatatatAn optional decimal digit string specifying the minimum field width.
274fc5c743eSuweNote that a leading zero is treated as the
275fc5c743eSuwe.Sq Cm 0
27614ef4b89Skreflag (above), subsequent embedded zeroes are part of the
277fc5c743eSuwe.Ar size .
278fc5c743eSuwe.It Ar prec
279ba4e8c96SatatatAn optional precision composed of a decimal point
280ba4e8c96Satatat.Sq Cm \&.
281ba4e8c96Satatatand a decimal digit string that indicates the maximum string length,
282ba4e8c96Satatatthe number of digits to appear after the decimal point in floating point
28314ef4b89Skreoutput, or the minimum number of digits to appear in other numeric output.
284fc5c743eSuwe.It Ar fmt
285b1017b64SwizAn optional output format specifier which is one of
286ba4e8c96Satatat.Cm D ,
287ba4e8c96Satatat.Cm O ,
288ba4e8c96Satatat.Cm U ,
289ba4e8c96Satatat.Cm X ,
290ba4e8c96Satatat.Cm F ,
291ba4e8c96Satatator
292ba4e8c96Satatat.Cm S .
293ba4e8c96SatatatThese represent signed decimal output, octal output, unsigned decimal
294ba4e8c96Satatatoutput, hexadecimal output, floating point output, and string output,
295be8ae688Sgrantrespectively.
296be8ae688SgrantSome output formats do not apply to all fields.
297ba4e8c96SatatatFloating point output only applies to timespec fields (the
298b1017b64Swiz.Cm a ,
299b1017b64Swiz.Cm m ,
300ba4e8c96Satatatand
301b1017b64Swiz.Cm c
302b1017b64Swizfields).
303ba4e8c96Satatat.Pp
30414ef4b89SkreThe special output format specifier
305ba4e8c96Satatat.Cm S
306ba4e8c96Satatatmay be used to indicate that the output, if
307be8ae688Sgrantapplicable, should be in string format.
308fc5c743eSuweMay be used in combination with the following field specifiers:
309fc5c743eSuwe.Bl -tag -width Cm
310fc5c743eSuwe.It Cm a , m , c
31174d5645fSwizDisplay date in
31274d5645fSwiz.Xr strftime 3
313fc5c743eSuweformat with the extension that
314fc5c743eSuwe.Ql %f
315fc5c743eSuweprints nanoseconds if available.
316fc5c743eSuwe.It Cm d , r
317ba4e8c96SatatatDisplay actual device name.
318*ed7b026dSchristos.It Cm f
319*ed7b026dSchristosDisplay the flags of
320*ed7b026dSchristos.Ar file
321*ed7b026dSchristosas in
322*ed7b026dSchristos.Nm ls Fl ldo .
323fc5c743eSuwe.It Cm g , u
324ba4e8c96SatatatDisplay group or user name.
325ba4e8c96Satatat.It Cm p
326ba4e8c96SatatatDisplay the mode of
327ba4e8c96Satatat.Ar file
328fc5c743eSuwesymbolically, as in
329c583268dSatatat.Ic ls -lTd .
330ba4e8c96Satatat.It Cm N
331ba4e8c96SatatatDisplays the name of
332ba4e8c96Satatat.Ar file .
333b1017b64Swiz.It Cm T
334ba4e8c96SatatatDisplays the type of
335ba4e8c96Satatat.Ar file .
336fc5c743eSuwe.It Cm R , Y
337fc5c743eSuweInsert a
338fc5c743eSuwe.Sq Li \~->\~ \" .Ql, but force quotes even in PS output
339fc5c743eSuweinto the output.
34014ef4b89SkreNote that the default output formats for
341ba4e8c96Satatat.Cm Y
34214ef4b89Skreand
34314ef4b89Skre.Cm R
34414ef4b89Skreare strings, if
34514ef4b89Skre.Cm S
34614ef4b89Skreis specified explicitly, these four characters are prepended.
347ba4e8c96Satatat.El
348fc5c743eSuwe.It Ar sub
349fc5c743eSuweAn optional sub field specifier: high, middle, or low.
350d05a0420SwizOnly applies to the
351ba4e8c96Satatat.Cm d ,
352fc5c743eSuwe.Cm N ,
353fc5c743eSuwe.Cm p ,
354ba4e8c96Satatat.Cm r ,
355277396bdSatatat.Cm T ,
356ba4e8c96Satatatand
357277396bdSatatat.Cm z
35814ef4b89Skreoutput field specifiers.
359be8ae688SgrantIt can be one of the following:
360fc5c743eSuwe.Bl -tag -width Cm
361ba4e8c96Satatat.It Cm H
362d05a0420Swiz.Dq High
363fc5c743eSuwesubfield of
364fc5c743eSuwe.Ar datum\^ :
365fc5c743eSuwe.Bl -tag -compact -width Cm
366277396bdSatatat.It Cm d , r
367277396bdSatatatMajor number for devices
368277396bdSatatat.It Cm N
369277396bdSatatatDirectory path of the file, similar to what
370fa01c2e8Satatat.Xr dirname 1
371277396bdSatatatwould show
372fc5c743eSuwe.It Cm p
373fc5c743eSuwe.Dq User
374fc5c743eSuwebits from the string form of permissions,
375fc5c743eSuweor the file
376fc5c743eSuwe.Dq type
377fc5c743eSuwebits from the numeric forms
378fc5c743eSuwe.It Cm T
379fc5c743eSuweThe long output form of file type
380277396bdSatatat.It Cm z
381277396bdSatatatFile size, rounded to the nearest gigabyte
382277396bdSatatat.El
383ba4e8c96Satatat.It Cm M
384d05a0420Swiz.Dq Middle
385fc5c743eSuwesubfield of
386fc5c743eSuwe.Ar datum\^ :
387fc5c743eSuwe.Bl -tag -compact -width Cm
388277396bdSatatat.It Cm p
389277396bdSatatatThe
390d05a0420Swiz.Dq group
391fc5c743eSuwebits from the string form of permissions,
392fc5c743eSuweor the
393d05a0420Swiz.Dq suid ,
394d05a0420Swiz.Dq sgid ,
395d05a0420Swizand
396d05a0420Swiz.Dq sticky
397277396bdSatatatbits from the numeric forms
398277396bdSatatat.It Cm z
399277396bdSatatatFile size, rounded to the nearest megabyte
400277396bdSatatat.El
401277396bdSatatat.It Cm L
402277396bdSatatat.Dq Low
403fc5c743eSuwesubfield of
404fc5c743eSuwe.Ar datum\^ :
405fc5c743eSuwe.Bl -tag -compact -width Cm
406fc5c743eSuwe.It Cm d , r
407277396bdSatatatMinor number for devices
408fc5c743eSuwe.It Cm N
409fc5c743eSuweBase filename of the file, similar to what
410fc5c743eSuwe.Xr basename 1
411fc5c743eSuwewould show
412277396bdSatatat.It Cm p
413277396bdSatatatThe
414277396bdSatatat.Dq other
415fc5c743eSuwebits from the string form of permissions,
416fc5c743eSuweor the
417277396bdSatatat.Dq user ,
418277396bdSatatat.Dq group ,
419277396bdSatatatand
420277396bdSatatat.Dq other
421277396bdSatatatbits from the numeric forms
422277396bdSatatat.It Cm T
423277396bdSatatatThe
424277396bdSatatat.Ic ls -F
425277396bdSatatatstyle output character for file type (the use of
426277396bdSatatat.Cm L
427277396bdSatatathere is optional)
428277396bdSatatat.It Cm z
429277396bdSatatatFile size, rounded to the nearest kilobyte
430277396bdSatatat.El
431ba4e8c96Satatat.El
432fc5c743eSuwe.It Ar datum
43314ef4b89SkreA required field specifier, ending the conversion specification,
43414ef4b89Skrebeing one of the following:
4354e8d1a3bSuwe.Bl -tag -width Cm
436ba4e8c96Satatat.It Cm d
437ba4e8c96SatatatDevice upon which
438ba4e8c96Satatat.Ar file
439ed200f58Swizresides
440ed200f58Swiz.Pq Fa st_dev .
441ba4e8c96Satatat.It Cm i
442b1017b64Swiz.Ar file Ap s
443ed200f58Swizinode number
444ed200f58Swiz.Pq Fa st_ino .
445ba4e8c96Satatat.It Cm p
446ed200f58SwizFile type and permissions
447ed200f58Swiz.Pq Fa st_mode .
448ba4e8c96Satatat.It Cm l
449ba4e8c96SatatatNumber of hard links to
450ed200f58Swiz.Ar file
451ed200f58Swiz.Pq Fa st_nlink .
452ba4e8c96Satatat.It Cm u , g
453ba4e8c96SatatatUser-id and group-id of
454b1017b64Swiz.Ar file Ap s
455ed200f58Swizowner
456ed200f58Swiz.Pq Fa st_uid , st_gid .
457ba4e8c96Satatat.It Cm r
458ed200f58SwizDevice number for character and block device special files
459ed200f58Swiz.Pq Fa st_rdev .
460ee00aa72Satatat.It Cm a , m , c , B
461ba4e8c96SatatatThe time
462ba4e8c96Satatat.Ar file
46314ef4b89Skrewas last accessed or modified, or when its inode was last changed, or
464ed200f58Swizthe birth time of the inode
465a798b8c1Sreed.Pq Fa st_atime , st_mtime , st_ctime , st_birthtime .
466ba4e8c96Satatat.It Cm z
467ba4e8c96SatatatThe size of
468ba4e8c96Satatat.Ar file
469ed200f58Swizin bytes
470ed200f58Swiz.Pq Fa st_size .
471ba4e8c96Satatat.It Cm b
472ba4e8c96SatatatNumber of blocks allocated for
473ed200f58Swiz.Ar file
474ed200f58Swiz.Pq Fa st_blocks .
475ba4e8c96Satatat.It Cm k
476ed200f58SwizOptimal file system I/O operation block size
477ed200f58Swiz.Pq Fa st_blksize .
478ba4e8c96Satatat.It Cm f
479ba4e8c96SatatatUser defined flags for
480ed200f58Swiz.Ar file
481ed200f58Swiz.Pq Fa st_flags .
482ba4e8c96Satatat.It Cm v
483ed200f58SwizInode generation number
484ed200f58Swiz.Pq Fa st_gen .
485ba4e8c96Satatat.El
486ba4e8c96Satatat.Pp
4872a7d09e7SeladThe following five field specifiers are not drawn directly from the
488fc5c743eSuwedata in
489fc5c743eSuwe.Vt struct stat ,
490fc5c743eSuwebut are:
4914e8d1a3bSuwe.Bl -tag -width Cm
492ba4e8c96Satatat.It Cm N
493ba4e8c96SatatatThe name of the file.
4942a7d09e7Selad.It Cm R
4952a7d09e7SeladThe absolute pathname corresponding to the file.
496ba4e8c96Satatat.It Cm T
497ba4e8c96SatatatThe file type, either as in
498ba4e8c96Satatat.Ic ls -F
499ba4e8c96Satatator in a more descriptive form if the sub field specifier
500ba4e8c96Satatat.Cm H
501ba4e8c96Satatatis given.
502ba4e8c96Satatat.It Cm Y
503ba4e8c96SatatatThe target of a symbolic link.
504ba4e8c96Satatat.It Cm Z
505d05a0420SwizExpands to
506fc5c743eSuwe.Dq Ar major Ns Li \&, Ns Ar minor\^
507fc5c743eSuwe.Po
508fc5c743eSuwethat is,
509fc5c743eSuwe.Sq Li %Hr,%-Lr
510fc5c743eSuwe.Pc
511fc5c743eSuwefor character or block special devices,
51214ef4b89Skreand gives size output
513fc5c743eSuwe.Pq Sq Li %z
514fc5c743eSuwefor all other file types.
5155996912dSkreA specified field width applies to the overall result
5165996912dSkre(approximately half each for the two device file sub-fields),
5175996912dSkrebut precision, output format, and flags are used separately for
5185996912dSkreeach conversion made (but note the
519fc5c743eSuwe.Sq Cm -
520fc5c743eSuwein the
521fc5c743eSuwe.Sq Li %-Lr
522fc5c743eSuweconversion.)
523ba4e8c96Satatat.El
524ba4e8c96Satatat.El
525ba4e8c96Satatat.Pp
526ba4e8c96SatatatOnly the
527fc5c743eSuwe.Sq Cm %
528fc5c743eSuweand the
529fc5c743eSuwe.Ar datum
530fc5c743eSuwe(field specifier) are required.
531be8ae688SgrantMost field specifiers default to
532ba4e8c96Satatat.Cm U
53314ef4b89Skreas an output format, with the
534ba4e8c96Satatatexception of
535ba4e8c96Satatat.Cm p
536ba4e8c96Satatatwhich defaults to
537e2d8a15cSwiz.Cm O ;
538ba4e8c96Satatat.Cm a , m ,
539ba4e8c96Satatatand
540ba4e8c96Satatat.Cm c
541ba4e8c96Satatatwhich default to
542e2d8a15cSwiz.Cm D ;
543ba4e8c96Satatatand
54414ef4b89Skre.Cm Y , T , R ,
545ba4e8c96Satatatand
546ba4e8c96Satatat.Cm N ,
547ba4e8c96Satatatwhich default to
548ba4e8c96Satatat.Cm S .
549ba4e8c96Satatat.Sh EXIT STATUS
550fc99b6a4Ssnj.Ex -std
551ba4e8c96Satatat.Sh EXAMPLES
55214ef4b89SkreIf no options are specified, the default format is:
5531575138bSyamt.Bd -literal -offset indent
55414ef4b89Skre%d %i %Sp %l %Su %Sg %r %z "%Sa" "%Sm" "%Sc" "%SB" %k %b %#Xf %N
5551575138bSyamt.Ed
5561575138bSyamt.Pp
55714ef4b89SkreThus:
558192ee4d0Swiz.Bd -literal -offset indent -compact
55914ef4b89Skre> stat /tmp/bar
56014ef4b89Skre0 78852 -rw-r--r-- 1 root wheel \(mi1 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
56114ef4b89Skre.Ed
56214ef4b89Skre.Pp
56314ef4b89SkreThis next example produces output very similar to that from
564fc5c743eSuwe.Ic find Ar \&.\|.\|. Ic -ls ,
565fc5c743eSuweexcept that
5667f5f7e4bSapb.Xr find 1
567229948abSapbdisplays the time in a different format, and
568229948abSapb.Xr find 1
5699438a85aSapbsometimes adds one or more spaces after the comma in
570fc5c743eSuwe.Dq Ar major Ns Li \&, Ns Ar minor\^
571fc5c743eSuwefor device nodes:
5727f5f7e4bSapb.Bd -literal -offset indent
57301869ca4Swiz> stat -f "%7i %6b %-11Sp %3l %-17Su %-17Sg %9Z %Sm %N%SY" /tmp/bar
5747f5f7e4bSapb  78852      0 -rw-r--r--    1 root              wheel                     0 Jul  8 10:26:03 2004 /tmp/bar
5757f5f7e4bSapb
57601869ca4Swiz> find /tmp/bar -ls -exit
5777f5f7e4bSapb  78852      0 -rw-r--r--    1 root              wheel                     0 Jul  8  2004 /tmp/bar
5787f5f7e4bSapb.Ed
5797f5f7e4bSapb.Pp
5807f5f7e4bSapbThis example produces output very similar to that from
581fc5c743eSuwe.Ic ls -lTd ,
582fc5c743eSuweexcept that
5837f5f7e4bSapb.Xr ls 1
584229948abSapbadjusts the column spacing differently when listing multiple files,
585fc5c743eSuweand adds at least one space after the comma in
586fc5c743eSuwe.Dq Ar major Ns Li \&, Ns Ar minor\^
587fc5c743eSuwefor device nodes:
5887f5f7e4bSapb.Bd -literal -offset indent
58901869ca4Swiz> stat -f "%-11Sp %l %Su  %Sg  %Z %Sm %N%SY" /tmp/bar
5907f5f7e4bSapb-rw-r--r--  1 root  wheel  0 Jul  8 10:26:03 2004 /tmp/bar
5917f5f7e4bSapb
59201869ca4Swiz> ls -lTd /tmp/bar
5937f5f7e4bSapb-rw-r--r--  1 root  wheel  0 Jul  8 10:26:03 2004 /tmp/bar
5947f5f7e4bSapb.Ed
5957f5f7e4bSapb.Pp
596d05a0420SwizGiven a symbolic link
597d05a0420Swiz.Pa /tmp/foo
598fc5c743eSuwethat points to
599d05a0420Swiz.Pa / ,
600d05a0420Swizyou would use
601ba4e8c96Satatat.Nm
602ba4e8c96Satatatas follows:
603ba4e8c96Satatat.Bd -literal -offset indent
60401869ca4Swiz> stat -F /tmp/foo
60501869ca4Swizlrwxrwxrwx 1 jschauma cs 1 Apr 24 16:37:28 2002 /tmp/foo@ -> /
606b1017b64Swiz
60701869ca4Swiz> stat -LF /tmp/foo
608ebe81c7eSatatatdrwxr-xr-x 16 root wheel 512 Apr 19 10:57:54 2002 /tmp/foo/
609ba4e8c96Satatat.Ed
610ba4e8c96Satatat.Pp
611fc5c743eSuweTo initialize some shell variables, you could use the
612ba4e8c96Satatat.Fl s
613ba4e8c96Satatatflag as follows:
614ba4e8c96Satatat.Bd -literal -offset indent
61501869ca4Swiz> csh
616ba4e8c96Satatat% eval set `stat -s .cshrc`
617075d5146Syamt% echo $st_size $st_mtime
618ba4e8c96Satatat1148 1015432481
619b1017b64Swiz
62001869ca4Swiz> sh
621ba4e8c96Satatat$ eval $(stat -s .profile)
622075d5146Syamt$ echo $st_size $st_mtime
623ba4e8c96Satatat1148 1015432481
624ba4e8c96Satatat.Ed
625ba4e8c96Satatat.Pp
626ba4e8c96SatatatIn order to get a list of the kind of files including files pointed to if the
627ba4e8c96Satatatfile is a symbolic link, you could use the following format:
628ba4e8c96Satatat.Bd -literal -offset indent
629ba4e8c96Satatat$ stat -f "%N: %HT%SY" /tmp/*
63001869ca4Swiz/tmp/bar: Symbolic Link -> /tmp/foo
631ba4e8c96Satatat/tmp/output25568: Regular File
632ba4e8c96Satatat/tmp/blah: Directory
63301869ca4Swiz/tmp/foo: Symbolic Link -> /
634ba4e8c96Satatat.Ed
635ba4e8c96Satatat.Pp
636ba4e8c96SatatatIn order to get a list of the devices, their types and the major and minor
637ba4e8c96Satatatdevice numbers, formatted with tabs and line breaks, you could use the
638ba4e8c96Satatatfollowing format:
639ba4e8c96Satatat.Bd -literal -offset indent
640ba4e8c96Satatatstat -f "Name: %N%n%tType: %HT%n%tMajor: %Hr%n%tMinor: %Lr%n%n" /dev/*
641ba4e8c96Satatat[...]
642ba4e8c96SatatatName: /dev/wt8
643ba4e8c96Satatat        Type: Block Device
644ba4e8c96Satatat        Major: 3
645ba4e8c96Satatat        Minor: 8
646b1017b64Swiz
647ba4e8c96SatatatName: /dev/zero
648ba4e8c96Satatat        Type: Character Device
649ba4e8c96Satatat        Major: 2
650ba4e8c96Satatat        Minor: 12
651ba4e8c96Satatat.Ed
652ba4e8c96Satatat.Pp
653ba4e8c96SatatatIn order to determine the permissions set on a file separately, you could use
654ba4e8c96Satatatthe following format:
655ba4e8c96Satatat.Bd -literal -offset indent
65601869ca4Swiz> stat -f "%Sp -> owner=%SHp group=%SMp other=%SLp" .
65701869ca4Swizdrwxr-xr-x -> owner=rwx group=r-x other=r-x
658ba4e8c96Satatat.Ed
659ba4e8c96Satatat.Pp
660b1017b64SwizIn order to determine the three files that have been modified most recently,
661b1017b64Swizyou could use the following format:
662ba4e8c96Satatat.Bd -literal -offset indent
66301869ca4Swiz> stat -f "%m%t%Sm %N" /tmp/* | sort -rn | head -3 | cut -f2-
664ba4e8c96SatatatApr 25 11:47:00 2002 /tmp/blah
665ba4e8c96SatatatApr 25 10:36:34 2002 /tmp/bar
666ba4e8c96SatatatApr 24 16:47:35 2002 /tmp/foo
667ba4e8c96Satatat.Ed
66864d2b8e0Sapb.Pp
66964d2b8e0SapbUser names, group names, and file names that contain spaces
67064d2b8e0Sapbor other special characters may be encoded in
67164d2b8e0Sapb.Xr vis 3
67264d2b8e0Sapbstyle, using the
673fc5c743eSuwe.Sq Cm \&#
674fc5c743eSuweflag:
67564d2b8e0Sapb.Bd -literal -offset indent
67601869ca4Swiz> ln -s 'target with spaces' 'link with spaces'
67701869ca4Swiz> stat -f "%#N%#SY" 'link with spaces'
67801869ca4Swizlink\eswith\esspaces -> target\eswith\esspaces
67964d2b8e0Sapb.Ed
680ba4e8c96Satatat.Sh SEE ALSO
681fa01c2e8Satatat.Xr basename 1 ,
682fa01c2e8Satatat.Xr dirname 1 ,
683fc5c743eSuwe.Xr find 1 ,
684ba4e8c96Satatat.Xr ls 1 ,
68514ef4b89Skre.Xr readlink 1 ,
68614ef4b89Skre.Xr fstat 2 ,
687ba4e8c96Satatat.Xr lstat 2 ,
688ba4e8c96Satatat.Xr readlink 2 ,
689ba4e8c96Satatat.Xr stat 2 ,
690ba4e8c96Satatat.Xr printf 3 ,
69114ef4b89Skre.Xr realpath 3 ,
692ba4e8c96Satatat.Xr strftime 3
693ba4e8c96Satatat.Sh HISTORY
694ba4e8c96SatatatThe
695ba4e8c96Satatat.Nm
696ba4e8c96Satatatutility appeared in
697ba4e8c96Satatat.Nx 1.6 .
698ba4e8c96Satatat.Sh AUTHORS
699d05a0420Swiz.An -nosplit
700ba4e8c96SatatatThe
701ba4e8c96Satatat.Nm
7022ceb8458Sgrantutility was written by
7032ceb8458Sgrant.An Andrew Brown
7042ceb8458Sgrant.Aq atatat@NetBSD.org .
7052ceb8458SgrantThis man page was written by
7062ceb8458Sgrant.An Jan Schaumann
7072ceb8458Sgrant.Aq jschauma@NetBSD.org .
708