xref: /dragonfly/usr.bin/stat/stat.1 (revision 8a7bdfea)
1.\"	$NetBSD: stat.1,v 1.11 2003/05/08 13:07:10 wiz Exp $
2.\"	$DragonFly: src/usr.bin/stat/stat.1,v 1.6 2007/11/04 16:33:19 swildner Exp $
3.\" Copyright (c) 2002 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Andrew Brown and Jan Schaumann.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
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.
17.\" 3. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"        This product includes software developed by the NetBSD
20.\"        Foundation, Inc. and its contributors.
21.\" 4. Neither the name of The NetBSD Foundation nor the names of its
22.\"    contributors may be used to endorse or promote products derived
23.\"    from this software without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35.\" POSSIBILITY OF SUCH DAMAGE.
36.\"
37.\" $FreeBSD: src/usr.bin/stat/stat.1,v 1.8 2005/06/14 11:50:53 ru Exp $
38.\"
39.Dd May 8, 2003
40.Dt STAT 1
41.Os
42.Sh NAME
43.Nm stat ,
44.Nm readlink
45.Nd display file status
46.Sh SYNOPSIS
47.Nm
48.Op Fl FLnq
49.Op Fl f Ar format | Fl l | r | s | x
50.Op Fl t Ar timefmt
51.Op Ar
52.Nm readlink
53.Op Fl n
54.Op Ar
55.Sh DESCRIPTION
56The
57.Nm
58utility displays information about the file pointed to by
59.Ar file .
60Read, write or execute permissions of the named file are not required, but
61all directories listed in the path name leading to the file must be
62searchable.
63If no argument is given,
64.Nm
65displays information about the file descriptor for standard input.
66.Pp
67When invoked as
68.Nm readlink ,
69only the target of the symbolic link is printed.
70If the given argument is not a symbolic link,
71.Nm readlink
72will print nothing and exit with an error.
73.Pp
74The information displayed is obtained by calling
75.Xr lstat 2
76with the given argument and evaluating the returned structure.
77.Pp
78The options are as follows:
79.Bl -tag -width indent
80.It Fl F
81As in
82.Xr ls 1 ,
83display a slash
84.Pq Ql /
85immediately after each pathname that is a directory,
86an asterisk
87.Pq Ql *
88after each that is executable,
89an at sign
90.Pq Ql @
91after each symbolic link,
92a percent sign
93.Pq Ql %
94after each whiteout,
95an equal sign
96.Pq Ql =
97after each socket,
98and a vertical bar
99.Pq Ql |
100after each that is a FIFO.
101The use of
102.Fl F
103implies
104.Fl l .
105.It Fl L
106Use
107.Xr stat 2
108instead of
109.Xr lstat 2 .
110The information reported by
111.Nm
112will refer to the target of
113.Ar file ,
114if file is a symbolic link, and not to
115.Ar file
116itself.
117.It Fl n
118Do not force a newline to appear at the end of each piece of output.
119.It Fl q
120Suppress failure messages if calls to
121.Xr stat 2
122or
123.Xr lstat 2
124fail.
125When run as
126.Nm readlink ,
127error messages are automatically suppressed.
128.It Fl f Ar format
129Display information using the specified format.
130See the
131.Sx Formats
132section for a description of valid formats.
133.It Fl l
134Display output in
135.Nm ls Fl lT
136format.
137.It Fl r
138Display raw information.
139That is, for all the fields in the
140.Vt stat
141structure,
142display the raw, numerical value (for example, times in seconds since the
143epoch, etc.).
144.It Fl s
145Display information in
146.Dq "shell output" ,
147suitable for initializing variables.
148.It Fl x
149Display information in a more verbose way as known from some
150.Tn Linux
151distributions.
152.It Fl t Ar timefmt
153Display timestamps using the specified format.
154This format is
155passed directly to
156.Xr strftime 3 .
157.El
158.Ss Formats
159Format strings are similar to
160.Xr printf 3
161formats in that they start with
162.Cm % ,
163are then followed by a sequence of formatting characters, and end in
164a character that selects the field of the
165.Vt "struct stat"
166which is to be formatted.
167If the
168.Cm %
169is immediately followed by one of
170.Cm n , t , % ,
171or
172.Cm @ ,
173then a newline character, a tab character, a percent character,
174or the current file number is printed, otherwise the string is
175examined for the following:
176.Pp
177Any of the following optional flags:
178.Bl -tag -width indent
179.It Cm #
180Selects an alternate output form for octal and hexadecimal output.
181Non-zero octal output will have a leading zero, and non-zero
182hexadecimal output will have
183.Dq Li 0x
184prepended to it.
185.It Cm +
186Asserts that a sign indicating whether a number is positive or negative
187should always be printed.
188Non-negative numbers are not usually printed
189with a sign.
190.It Cm -
191Aligns string output to the left of the field, instead of to the right.
192.It Cm 0
193Sets the fill character for left padding to the
194.Ql 0
195character, instead of a space.
196.It space
197Reserves a space at the front of non-negative signed output fields.
198A
199.Sq Cm +
200overrides a space if both are used.
201.El
202.Pp
203Then the following fields:
204.Bl -tag -width indent
205.It Ar size
206An optional decimal digit string specifying the minimum field width.
207.It Ar prec
208An optional precision composed of a decimal point
209.Sq Cm \&.
210and a decimal digit string that indicates the maximum string length,
211the number of digits to appear after the decimal point in floating point
212output, or the minimum number of digits to appear in numeric output.
213.It Ar fmt
214An optional output format specifier which is one of
215.Cm D , O , U , X , F ,
216or
217.Cm S .
218These represent signed decimal output, octal output, unsigned decimal
219output, hexadecimal output, floating point output, and string output,
220respectively.
221Some output formats do not apply to all fields.
222Floating point output only applies to
223.Vt timespec
224fields (the
225.Cm a , m ,
226and
227.Cm c
228fields).
229.Pp
230The special output specifier
231.Cm S
232may be used to indicate that the output, if
233applicable, should be in string format.
234May be used in combination with:
235.Bl -tag -width indent
236.It Cm amc
237Display date in
238.Xr strftime 3
239format.
240.It Cm dr
241Display actual device name.
242.It Cm gu
243Display group or user name.
244.It Cm p
245Display the mode of
246.Ar file
247as in
248.Nm ls Fl lTd .
249.It Cm N
250Displays the name of
251.Ar file .
252.It Cm T
253Displays the type of
254.Ar file .
255.It Cm Y
256Insert a
257.Dq Li " -\*[Gt] "
258into the output.
259Note that the default output format
260for
261.Cm Y
262is a string, but if specified explicitly, these four characters are
263prepended.
264.El
265.It Ar sub
266An optional sub field specifier (high, middle, low).
267Only applies to
268the
269.Cm p , d , r ,
270and
271.Cm T
272output formats.
273It can be one of the following:
274.Bl -tag -width indent
275.It Cm H
276.Dq High
277\(em
278specifies the major number for devices from
279.Cm r
280or
281.Cm d ,
282the
283.Dq user
284bits for permissions from the string form of
285.Cm p ,
286the file
287.Dq type
288bits from the numeric forms of
289.Cm p ,
290and the long output form of
291.Cm T .
292.It Cm L
293.Dq Low
294\(em
295specifies the minor number for devices from
296.Cm r
297or
298.Cm d ,
299the
300.Dq other
301bits for permissions from the string form of
302.Cm p ,
303the
304.Dq user ,
305.Dq group ,
306and
307.Dq other
308bits from the numeric forms of
309.Cm p ,
310and the
311.Nm ls Fl F
312style output character for file type when used with
313.Cm T
314(the use of
315.Cm L
316for this is optional).
317.It Cm M
318.Dq Middle
319\(em
320specifies the
321.Dq group
322bits for permissions from the
323string output form of
324.Cm p ,
325or the
326.Dq suid ,
327.Dq sgid ,
328and
329.Dq sticky
330bits for the numeric forms of
331.Cm p .
332.El
333.It Ar datum
334A required field specifier, being one of the following:
335.Bl -tag -width indent
336.It Cm d
337Device upon which
338.Ar file
339resides.
340.It Cm i
341.Ar file Ns 's
342inode number.
343.It Cm p
344File type and permissions.
345.It Cm l
346Number of hard links to
347.Ar file .
348.It Cm u , g
349User ID and group ID of
350.Ar file Ns 's
351owner.
352.It Cm r
353Device number for character and block device special files.
354.It Cm a , m , c , B
355The time
356.Ar file
357was last accessed or modified, or when the inode was last changed, or
358the birth time of the inode.
359.It Cm z
360The size of
361.Ar file
362in bytes.
363.It Cm b
364Number of blocks allocated for
365.Ar file .
366.It Cm k
367Optimal file system I/O operation block size.
368.It Cm f
369User defined flags for
370.Ar file .
371.It Cm v
372Inode generation number.
373.El
374.Pp
375The following four field specifiers are not drawn directly from the
376data in
377.Vt "struct stat" ,
378but are:
379.Bl -tag -width indent
380.It Cm N
381The name of the file.
382.It Cm T
383The file type, either as in
384.Nm ls Fl F
385or in a more descriptive form if the
386.Ar sub
387field specifier
388.Cm H
389is given.
390.It Cm Y
391The target of a symbolic link.
392.It Cm Z
393Expands to
394.Dq major,minor
395from the
396.Va rdev
397field for character or block
398special devices and gives size output for all others.
399.El
400.El
401.Pp
402Only the
403.Cm %
404and the field specifier are required.
405Most field specifiers default to
406.Cm U
407as an output form, with the
408exception of
409.Cm p
410which defaults to
411.Cm O ,
412.Cm a , m ,
413and
414.Cm c
415which default to
416.Cm D ,
417and
418.Cm Y , T ,
419and
420.Cm N
421which default to
422.Cm S .
423.Sh EXAMPLES
424Given a symbolic link
425.Pa foo
426that points from
427.Pa /tmp/foo
428to
429.Pa / ,
430you would use
431.Nm
432as follows:
433.Bd -literal -offset indent
434\*[Gt] stat -F /tmp/foo
435lrwxrwxrwx 1 jschauma cs 1 Apr 24 16:37:28 2002 /tmp/foo@ -\*[Gt] /
436
437\*[Gt] stat -LF /tmp/foo
438drwxr-xr-x 16 root wheel 512 Apr 19 10:57:54 2002 /tmp/foo/
439.Ed
440.Pp
441To initialize some shell variables, you could use the
442.Fl s
443flag as follows:
444.Bd -literal -offset indent
445\*[Gt] csh
446% eval set `stat -s .cshrc`
447% echo $st_size $st_mtimespec
4481148 1015432481
449
450\*[Gt] sh
451$ eval $(stat -s .profile)
452$ echo $st_size $st_mtimespec
4531148 1015432481
454.Ed
455.Pp
456In order to get a list of the kind of files including files pointed to if the
457file is a symbolic link, you could use the following format:
458.Bd -literal -offset indent
459$ stat -f "%N: %HT%SY" /tmp/*
460/tmp/bar: Symbolic Link -\*[Gt] /tmp/foo
461/tmp/output25568: Regular File
462/tmp/blah: Directory
463/tmp/foo: Symbolic Link -\*[Gt] /
464.Ed
465.Pp
466In order to get a list of the devices, their types and the major and minor
467device numbers, formatted with tabs and linebreaks, you could use the
468following format:
469.Bd -literal -offset indent
470stat -f "Name: %N%n%tType: %HT%n%tMajor: %Hr%n%tMinor: %Lr%n%n" /dev/*
471[...]
472Name: /dev/wt8
473        Type: Block Device
474        Major: 3
475        Minor: 8
476
477Name: /dev/zero
478        Type: Character Device
479        Major: 2
480        Minor: 12
481.Ed
482.Pp
483In order to determine the permissions set on a file separately, you could use
484the following format:
485.Bd -literal -offset indent
486\*[Gt] stat -f "%Sp -\*[Gt] owner=%SHp group=%SMp other=%SLp" .
487drwxr-xr-x -\*[Gt] owner=rwx group=r-x other=r-x
488.Ed
489.Pp
490In order to determine the three files that have been modified most recently,
491you could use the following format:
492.Bd -literal -offset indent
493\*[Gt] stat -f "%m%t%Sm %N" /tmp/* | sort -rn | head -3 | cut -f2-
494Apr 25 11:47:00 2002 /tmp/blah
495Apr 25 10:36:34 2002 /tmp/bar
496Apr 24 16:47:35 2002 /tmp/foo
497.Ed
498.Sh DIAGNOSTICS
499.Ex -std stat readlink
500.Sh SEE ALSO
501.Xr file 1 ,
502.Xr ls 1 ,
503.Xr lstat 2 ,
504.Xr readlink 2 ,
505.Xr stat 2 ,
506.Xr printf 3 ,
507.Xr strftime 3
508.Sh HISTORY
509The
510.Nm
511utility appeared in
512.Nx 1.6
513and
514.Fx 4.10 .
515.Sh AUTHORS
516.An -nosplit
517The
518.Nm
519utility was written by
520.An Andrew Brown
521.Aq atatat@NetBSD.org .
522This man page was written by
523.An Jan Schaumann
524.Aq jschauma@NetBSD.org .
525