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