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