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