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