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