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.\" Copyright (c) 2025 Klara, Inc. 10.\" 11.\" Redistribution and use in source and binary forms, with or without 12.\" modification, are permitted provided that the following conditions 13.\" are met: 14.\" 1. Redistributions of source code must retain the above copyright 15.\" notice, this list of conditions and the following disclaimer. 16.\" 2. Redistributions in binary form must reproduce the above copyright 17.\" notice, this list of conditions and the following disclaimer in the 18.\" documentation and/or other materials provided with the distribution. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30.\" POSSIBILITY OF SUCH DAMAGE. 31.\" 32.Dd October 1, 2026 33.Dt STAT 1 34.Os 35.Sh NAME 36.Nm stat , 37.Nm readlink , 38.Nm mountpoint 39.Nd display file status 40.Sh SYNOPSIS 41.Nm 42.Op Fl FHhLnq 43.Op Fl f Ar format | Fl l | r | s | x 44.Op Fl t Ar timefmt 45.Op Ar 46.Nm readlink 47.Op Fl fn 48.Op Ar 49.Nm mountpoint 50.Op Fl q 51.Ar file 52.Sh DESCRIPTION 53The 54.Nm 55utility displays information about the file pointed to by 56.Ar file . 57Read, write, or execute permissions of the named file are not required, but 58all directories listed in the pathname leading to the file must be 59searchable. 60If no argument is given, 61.Nm 62displays information about the file descriptor for standard input. 63.Pp 64When invoked as 65.Nm readlink , 66only the target of the symbolic link is printed. 67If the given argument is not a symbolic link and the 68.Fl f 69option is not specified, 70.Nm readlink 71will print nothing and exit with an error. 72If the 73.Fl f 74option is specified, the output is canonicalized by following every symlink 75in every component of the given path recursively. 76.Nm readlink 77will resolve both absolute and relative paths, and return the absolute pathname 78corresponding to 79.Ar file . 80In this case, the argument does not need to be a symbolic link. 81.Pp 82When invoked as 83.Nm mountpoint , 84the utility checks whether 85.Ar file 86is the root of a mounted file system. 87This is usually a directory, but file systems such as 88.Xr nullfs 5 89can also be mounted over regular files and sockets. 90Symbolic links are followed. 91Unless the 92.Fl q 93option is given, a message stating whether 94.Ar file 95is a mount point is written to the standard output. 96Error messages are written to the standard error even with 97.Fl q . 98.Pp 99The information displayed is obtained by calling 100.Xr lstat 2 101with the given argument and evaluating the returned structure. 102When invoked as 103.Nm mountpoint , 104.Xr stat 2 105is called instead and the 106.Dv SFBSD_MNTPOINT 107flag in the 108.Fa st_bsdflags 109field is checked. 110The default format displays the 111.Fa st_dev , 112.Fa st_ino , 113.Fa st_mode , 114.Fa st_nlink , 115.Fa st_uid , 116.Fa st_gid , 117.Fa st_rdev , 118.Fa st_size , 119.Fa st_atime , 120.Fa st_mtime , 121.Fa st_ctime , 122.Fa st_birthtime , 123.Fa st_blksize , 124.Fa st_blocks , 125and 126.Fa st_flags 127fields, in that order. 128.Pp 129The options are as follows: 130.Bl -tag -width indent 131.It Fl F 132As in 133.Xr ls 1 , 134display a slash 135.Pq Ql / 136immediately after each pathname that is a directory, 137an asterisk 138.Pq Ql * 139after each that is executable, 140an at sign 141.Pq Ql @ 142after each symbolic link, 143a percent sign 144.Pq Ql % 145after each whiteout, 146an equal sign 147.Pq Ql = 148after each socket, 149and a vertical bar 150.Pq Ql | 151after each that is a FIFO. 152The use of 153.Fl F 154implies 155.Fl l . 156.It Fl H 157Treat each argument as the hexadecimal representation of an NFS file handle, 158and use 159.Xr fhstat 2 160instead of 161.Xr lstat 2 . 162This requires root privileges. 163.It Fl h 164For each file argument, print a line consisting of a comma-separated 165list of holes, a space, and the file name. 166Each hole is reported as its starting offset as a decimal number 167followed by a hyphen and the ending offset (one less than the starting 168offset of the data region that follows the hole) as a decimal number. 169If the file ends in a hole, the ending offset of the final hole will 170be one less than the size of the file. 171Otherwise, the final entry in the list (indeed, the only entry in the 172list, if the file is not sparse), is a single decimal number 173corresponding to the size of the file, representing the virtual hole 174at the end of the file. 175.Pp 176If the argument is a directory, instead of a list of holes, a single 177number is printed, corresponding to the minimum hole size for that 178directory as reported by 179.Xr pathconf 2 , 180followed by a space and the directory name. 181.Pp 182Please note that the only way to retrieve information about the holes 183in a file is to open it and walk the list of holes and data regions 184using 185.Xr lseek 2 . 186If the file is being modified by another process at the same time as 187.Nm 188is inspecting it, the result may be inconsistent. 189.Pp 190This option cannot be combined with the 191.Fl F , 192.Fl f , 193.Fl H , 194.Fl L , 195.Fl l , 196.Fl r , 197.Fl s , 198.Fl t , 199or 200.Fl x 201options. 202.It Fl L 203Use 204.Xr stat 2 205instead of 206.Xr lstat 2 . 207The information reported by 208.Nm 209will refer to the target of 210.Ar file , 211if file is a symbolic link, and not to 212.Ar file 213itself. 214If the link is broken or the target does not exist, 215fall back on 216.Xr lstat 2 217and report information about the link. 218.It Fl n 219Do not force a newline to appear at the end of each piece of output. 220.It Fl q 221Suppress failure messages if calls to 222.Xr stat 2 223or 224.Xr lstat 2 225fail. 226When run as 227.Nm readlink , 228error messages are automatically suppressed. 229When run as 230.Nm mountpoint , 231.Fl q 232suppresses the normal output instead; 233error messages are still written to the standard error. 234.It Fl f Ar format 235Display information using the specified format. 236See the 237.Sx Formats 238section for a description of valid formats. 239.It Fl l 240Display output in 241.Nm ls Fl lT 242format. 243.It Fl r 244Display raw information. 245That is, for all the fields in the 246.Vt stat 247structure, 248display the raw, numerical value (for example, times in seconds since the 249epoch, etc.). 250.It Fl s 251Display information in 252.Dq shell output 253format, 254suitable for initializing variables. 255.It Fl t Ar timefmt 256Display timestamps using the specified format. 257This format is 258passed directly to 259.Xr strftime 3 . 260.It Fl x 261Display information in a more verbose way as known from some 262.Tn Linux 263distributions. 264.El 265.Ss Formats 266Format strings are similar to 267.Xr printf 3 268formats in that they start with 269.Cm % , 270are then followed by a sequence of formatting characters, and end in 271a character that selects the field of the 272.Vt "struct stat" 273which is to be formatted. 274If the 275.Cm % 276is immediately followed by one of 277.Cm n , t , % , 278or 279.Cm @ , 280then a newline character, a tab character, a percent character, 281or the current file number is printed, otherwise the string is 282examined for the following: 283.Pp 284Any of the following optional flags: 285.Bl -tag -width indent 286.It Cm # 287Selects an alternate output form for octal and hexadecimal output. 288Non-zero octal output will have a leading zero, and non-zero 289hexadecimal output will have 290.Dq Li 0x 291prepended to it. 292.It Cm + 293Asserts that a sign indicating whether a number is positive or negative 294should always be printed. 295Non-negative numbers are not usually printed 296with a sign. 297.It Cm - 298Aligns string output to the left of the field, instead of to the right. 299.It Cm 0 300Sets the fill character for left padding to the 301.Ql 0 302character, instead of a space. 303.It space 304Reserves a space at the front of non-negative signed output fields. 305A 306.Sq Cm + 307overrides a space if both are used. 308.El 309.Pp 310Then the following fields: 311.Bl -tag -width indent 312.It Ar size 313An optional decimal digit string specifying the minimum field width. 314.It Ar prec 315An optional precision composed of a decimal point 316.Sq Cm \&. 317and a decimal digit string that indicates the maximum string length, 318the number of digits to appear after the decimal point in floating point 319output, or the minimum number of digits to appear in numeric output. 320.It Ar fmt 321An optional output format specifier which is one of 322.Cm D , O , U , X , F , 323or 324.Cm S . 325These represent signed decimal output, octal output, unsigned decimal 326output, hexadecimal output, floating point output, and string output, 327respectively. 328Some output formats do not apply to all fields. 329Floating point output only applies to 330.Vt timespec 331fields (the 332.Cm a , m , 333and 334.Cm c 335fields). 336.Pp 337The special output specifier 338.Cm S 339may be used to indicate that the output, if 340applicable, should be in string format. 341May be used in combination with: 342.Bl -tag -width indent 343.It Cm amc 344Display date in 345.Xr strftime 3 346format. 347.It Cm dr 348Display actual device name. 349.It Cm f 350Display the flags of 351.Ar file 352as in 353.Nm ls Fl lTdo . 354.It Cm gu 355Display group or user name. 356.It Cm p 357Display the mode of 358.Ar file 359as in 360.Nm ls Fl lTd . 361.It Cm N 362Displays the name of 363.Ar file . 364.It Cm T 365Displays the type of 366.Ar file . 367.It Cm Y 368Insert a 369.Dq Li " -\*[Gt] " 370into the output. 371Note that the default output format 372for 373.Cm Y 374is a string, but if specified explicitly, these four characters are 375prepended. 376.El 377.It Ar sub 378An optional sub field specifier (high, middle, low). 379Only applies to 380the 381.Cm p , d , r , 382and 383.Cm T 384output formats. 385It can be one of the following: 386.Bl -tag -width indent 387.It Cm H 388.Dq High 389\[em] 390specifies the major number for devices from 391.Cm r 392or 393.Cm d , 394the 395.Dq user 396bits for permissions from the string form of 397.Cm p , 398the file 399.Dq type 400bits from the numeric forms of 401.Cm p , 402and the long output form of 403.Cm T . 404.It Cm L 405.Dq Low 406\[em] 407specifies the minor number for devices from 408.Cm r 409or 410.Cm d , 411the 412.Dq other 413bits for permissions from the string form of 414.Cm p , 415the 416.Dq user , 417.Dq group , 418and 419.Dq other 420bits from the numeric forms of 421.Cm p , 422and the 423.Nm ls Fl F 424style output character for file type when used with 425.Cm T 426(the use of 427.Cm L 428for this is optional). 429.It Cm M 430.Dq Middle 431\[em] 432specifies the 433.Dq group 434bits for permissions from the 435string output form of 436.Cm p , 437or the 438.Dq suid , 439.Dq sgid , 440and 441.Dq sticky 442bits for the numeric forms of 443.Cm p . 444.El 445.It Ar datum 446A required field specifier, being one of the following: 447.Bl -tag -width indent 448.It Cm d 449Device upon which 450.Ar file 451resides 452.Pq Fa st_dev . 453.It Cm i 454.Ar file Ns 's 455inode number 456.Pq Fa st_ino . 457.It Cm p 458File type and permissions 459.Pq Fa st_mode . 460.It Cm l 461Number of hard links to 462.Ar file 463.Pq Fa st_nlink . 464.It Cm u , g 465User ID and group ID of 466.Ar file Ns 's 467owner 468.Pq Fa st_uid , st_gid . 469.It Cm r 470Device number for character and block device special files 471.Pq Fa st_rdev . 472.It Cm a , m , c , B 473The time 474.Ar file 475was last accessed or modified, or when the inode was last changed, or 476the birth time of the inode 477.Pq Fa st_atime , st_mtime , st_ctime , st_birthtime . 478.It Cm z 479The size of 480.Ar file 481in bytes 482.Pq Fa st_size . 483.It Cm b 484Number of blocks allocated for 485.Ar file 486.Pq Fa st_blocks . 487.It Cm k 488Optimal file system I/O operation block size 489.Pq Fa st_blksize . 490.It Cm f 491User defined flags for 492.Ar file . 493.It Cm v 494Inode generation number 495.Pq Fa st_gen . 496.El 497.Pp 498The following five field specifiers are not drawn directly from the 499data in 500.Vt "struct stat" , 501but are: 502.Bl -tag -width indent 503.It Cm N 504The name of the file. 505.It Cm R 506The absolute pathname corresponding to the file. 507.It Cm T 508The file type, either as in 509.Nm ls Fl F 510or in a more descriptive form if the 511.Ar sub 512field specifier 513.Cm H 514is given. 515.It Cm Y 516The target of a symbolic link. 517.It Cm Z 518Expands to 519.Dq major,minor 520from the 521.Va rdev 522field for character or block 523special devices and gives size output for all others. 524.El 525.El 526.Pp 527Only the 528.Cm % 529and the field specifier are required. 530Most field specifiers default to 531.Cm U 532as an output form, with the 533exception of 534.Cm p 535which defaults to 536.Cm O ; 537.Cm a , m , 538and 539.Cm c 540which default to 541.Cm D ; 542and 543.Cm Y , T , 544and 545.Cm N 546which default to 547.Cm S . 548.Sh EXIT STATUS 549.Ex -std stat readlink 550.Pp 551The 552.Nm mountpoint 553utility exits 0 if 554.Ar file 555is a mount point, 1 if it is not, and 2 if an error occurred. 556.Sh EXAMPLES 557If no options are specified, the default format is 558"%d %i %Sp %l %Su %Sg %r %z \e"%Sa\e" \e"%Sm\e" \e"%Sc\e" \e"%SB\e" %k %b %#Xf %N". 559.Bd -literal -offset indent 560\*[Gt] stat /tmp/bar 5610 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 562.Ed 563.Pp 564Given a symbolic link 565.Dq foo 566that points from 567.Pa /tmp/foo 568to 569.Pa / , 570you would use 571.Nm 572as follows: 573.Bd -literal -offset indent 574\*[Gt] stat -F /tmp/foo 575lrwxrwxrwx 1 jschauma cs 1 Apr 24 16:37:28 2002 /tmp/foo@ -\*[Gt] / 576 577\*[Gt] stat -LF /tmp/foo 578drwxr-xr-x 16 root wheel 512 Apr 19 10:57:54 2002 /tmp/foo/ 579.Ed 580.Pp 581To initialize some shell variables, you could use the 582.Fl s 583flag as follows: 584.Bd -literal -offset indent 585\*[Gt] csh 586% eval set `stat -s .cshrc` 587% echo $st_size $st_mtimespec 5881148 1015432481 589 590\*[Gt] sh 591$ eval $(stat -s .profile) 592$ echo $st_size $st_mtimespec 5931148 1015432481 594.Ed 595.Pp 596In order to get a list of file types including files pointed to if the 597file is a symbolic link, you could use the following format: 598.Bd -literal -offset indent 599$ stat -f "%N: %HT%SY" /tmp/* 600/tmp/bar: Symbolic Link -\*[Gt] /tmp/foo 601/tmp/output25568: Regular File 602/tmp/blah: Directory 603/tmp/foo: Symbolic Link -\*[Gt] / 604.Ed 605.Pp 606In order to get a list of the devices, their types and the major and minor 607device numbers, formatted with tabs and linebreaks, you could use the 608following format: 609.Bd -literal -offset indent 610stat -f "Name: %N%n%tType: %HT%n%tMajor: %Hr%n%tMinor: %Lr%n%n" /dev/* 611[...] 612Name: /dev/wt8 613 Type: Block Device 614 Major: 3 615 Minor: 8 616 617Name: /dev/zero 618 Type: Character Device 619 Major: 2 620 Minor: 12 621.Ed 622.Pp 623In order to determine the permissions set on a file separately, you could use 624the following format: 625.Bd -literal -offset indent 626\*[Gt] stat -f "%Sp -\*[Gt] owner=%SHp group=%SMp other=%SLp" . 627drwxr-xr-x -\*[Gt] owner=rwx group=r-x other=r-x 628.Ed 629.Pp 630In order to determine the three files that have been modified most recently, 631you could use the following format: 632.Bd -literal -offset indent 633\*[Gt] stat -f "%m%t%Sm %N" /tmp/* | sort -rn | head -3 | cut -f2- 634Apr 25 11:47:00 2002 /tmp/blah 635Apr 25 10:36:34 2002 /tmp/bar 636Apr 24 16:47:35 2002 /tmp/foo 637.Ed 638.Pp 639To display a file's modification time: 640.Bd -literal -offset indent 641\*[Gt] stat -f %m /tmp/foo 6421177697733 643.Ed 644.Pp 645To display the same modification time in a readable format: 646.Bd -literal -offset indent 647\*[Gt] stat -f %Sm /tmp/foo 648Apr 27 11:15:33 2007 649.Ed 650.Pp 651To display the same modification time in a readable and sortable format: 652.Bd -literal -offset indent 653\*[Gt] stat -f %Sm -t %Y%m%d%H%M%S /tmp/foo 65420070427111533 655.Ed 656.Pp 657To display the same in UTC: 658.Bd -literal -offset indent 659\*[Gt] sh 660$ TZ= stat -f %Sm -t %Y%m%d%H%M%S /tmp/foo 66120070427181533 662.Ed 663.Pp 664To check whether a directory is a mount point: 665.Bd -literal -offset indent 666\*[Gt] mountpoint /dev 667/dev is a mount point 668\*[Gt] mountpoint /usr/bin 669/usr/bin is not a mount point 670.Ed 671.Pp 672To mount a file system only if nothing is mounted there yet: 673.Bd -literal -offset indent 674$ mountpoint -q /mnt || mount /dev/md0 /mnt 675.Ed 676.Sh SEE ALSO 677.Xr file 1 , 678.Xr ls 1 , 679.Xr lstat 2 , 680.Xr readlink 2 , 681.Xr stat 2 , 682.Xr printf 3 , 683.Xr strftime 3 , 684.Xr nullfs 5 , 685.Xr mount 8 686.Sh HISTORY 687The 688.Nm 689utility appeared in 690.Nx 1.6 691and 692.Fx 4.10 . 693.Sh AUTHORS 694.An -nosplit 695The 696.Nm 697utility was written by 698.An Andrew Brown Aq Mt atatat@NetBSD.org . 699This man page was written by 700.An Jan Schaumann Aq Mt jschauma@NetBSD.org . 701