freebsd-skq/usr.bin/stat/stat.1

577 lines
13 KiB
Groff
Raw Normal View History

.\" $NetBSD: stat.1,v 1.19 2006/10/07 10:41:50 elad Exp $
2002-06-06 19:27:17 +00:00
.\"
.\" Copyright (c) 2002 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Andrew Brown and Jan Schaumann.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.\" $FreeBSD$
.\"
.Dd April 24, 2010
2002-06-06 19:27:17 +00:00
.Dt STAT 1
.Os
.Sh NAME
.Nm stat ,
.Nm readlink
2002-06-06 19:27:17 +00:00
.Nd display file status
.Sh SYNOPSIS
.Nm
.Op Fl FLnq
2003-06-02 11:19:24 +00:00
.Op Fl f Ar format | Fl l | r | s | x
2002-06-06 19:27:17 +00:00
.Op Fl t Ar timefmt
.Op Ar
.Nm readlink
.Op Fl fn
.Op Ar
2002-06-06 19:27:17 +00:00
.Sh DESCRIPTION
The
.Nm
utility displays information about the file pointed to by
.Ar file .
Read, write, or execute permissions of the named file are not required, but
all directories listed in the pathname leading to the file must be
searchable.
If no argument is given,
2002-06-06 19:27:17 +00:00
.Nm
displays information about the file descriptor for standard input.
.Pp
When invoked as
.Nm readlink ,
only the target of the symbolic link is printed.
If the given argument is not a symbolic link and the
.Fl f
option is not specified,
.Nm readlink
will print nothing and exit with an error.
If the
.Fl f
option is specified, the output is canonicalized by following every symlink
in every component of the given path recursively.
.Nm readlink
will resolve both absolute and relative paths, and return the absolute pathname
corresponding to
.Ar file .
In this case, the argument does not need to be a symbolic link.
.Pp
2002-06-06 19:27:17 +00:00
The information displayed is obtained by calling
.Xr lstat 2
with the given argument and evaluating the returned structure.
.Pp
The options are as follows:
2003-06-02 11:19:24 +00:00
.Bl -tag -width indent
2002-06-06 19:27:17 +00:00
.It Fl F
As in
2003-06-02 11:19:24 +00:00
.Xr ls 1 ,
display a slash
.Pq Ql /
immediately after each pathname that is a directory,
an asterisk
.Pq Ql *
after each that is executable,
an at sign
.Pq Ql @
after each symbolic link,
a percent sign
.Pq Ql %
after each whiteout,
an equal sign
.Pq Ql =
after each socket,
and a vertical bar
.Pq Ql |
after each that is a FIFO.
The use of
2002-06-06 19:27:17 +00:00
.Fl F
implies
.Fl l .
.It Fl L
Use
.Xr stat 2
instead of
.Xr lstat 2 .
The information reported by
.Nm
will refer to the target of
.Ar file ,
if file is a symbolic link, and not to
.Ar file
itself.
If the link is broken or the target does not exist,
fall back on
.Xr lstat 2
and report information about the link.
.It Fl l
Display output in
.Ic ls Fl lT
format.
2002-06-06 19:27:17 +00:00
.It Fl n
Do not force a newline to appear at the end of each piece of output.
.It Fl q
Suppress failure messages if calls to
.Xr stat 2
or
.Xr lstat 2
fail.
When run as
.Nm readlink ,
error messages are automatically suppressed.
2002-06-06 19:27:17 +00:00
.It Fl f Ar format
Display information using the specified format.
2003-05-21 21:07:28 +00:00
See the
.Sx Formats
2003-05-21 21:07:28 +00:00
section for a description of valid formats.
2002-06-06 19:27:17 +00:00
.It Fl l
Display output in
2003-06-02 11:19:24 +00:00
.Nm ls Fl lT
2002-06-06 19:27:17 +00:00
format.
.It Fl r
Display raw information.
2003-06-02 11:19:24 +00:00
That is, for all the fields in the
.Vt stat
structure,
2002-06-06 19:27:17 +00:00
display the raw, numerical value (for example, times in seconds since the
2003-06-02 11:19:24 +00:00
epoch, etc.).
2002-06-06 19:27:17 +00:00
.It Fl s
2003-06-02 11:19:24 +00:00
Display information in
.Dq shell output
format,
2003-06-02 11:19:24 +00:00
suitable for initializing variables.
2002-06-06 19:27:17 +00:00
.It Fl x
2003-06-02 11:19:24 +00:00
Display information in a more verbose way as known from some
.Tn Linux
2002-06-06 19:27:17 +00:00
distributions.
.It Fl t Ar timefmt
Display timestamps using the specified format.
This format is
2002-06-06 19:27:17 +00:00
passed directly to
.Xr strftime 3 .
.El
2003-06-02 11:19:24 +00:00
.Ss Formats
2002-06-06 19:27:17 +00:00
Format strings are similar to
.Xr printf 3
formats in that they start with
.Cm % ,
are then followed by a sequence of formatting characters, and end in
2003-06-02 11:19:24 +00:00
a character that selects the field of the
.Vt "struct stat"
which is to be formatted.
If the
2002-06-06 19:27:17 +00:00
.Cm %
is immediately followed by one of
2003-06-02 11:19:24 +00:00
.Cm n , t , % ,
2002-06-06 19:27:17 +00:00
or
.Cm @ ,
then a newline character, a tab character, a percent character,
or the current file number is printed, otherwise the string is
examined for the following:
.Pp
Any of the following optional flags:
2003-06-02 11:19:24 +00:00
.Bl -tag -width indent
2002-06-06 19:27:17 +00:00
.It Cm #
Selects an alternate output form for octal and hexadecimal output.
Non-zero octal output will have a leading zero, and non-zero
2003-06-02 11:19:24 +00:00
hexadecimal output will have
.Dq Li 0x
prepended to it.
2002-06-06 19:27:17 +00:00
.It Cm +
Asserts that a sign indicating whether a number is positive or negative
should always be printed.
Non-negative numbers are not usually printed
2002-06-06 19:27:17 +00:00
with a sign.
.It Cm -
Aligns string output to the left of the field, instead of to the right.
.It Cm 0
2003-06-02 11:19:24 +00:00
Sets the fill character for left padding to the
.Ql 0
character, instead of a space.
2002-06-06 19:27:17 +00:00
.It space
Reserves a space at the front of non-negative signed output fields.
A
2002-06-06 19:27:17 +00:00
.Sq Cm +
overrides a space if both are used.
.El
.Pp
Then the following fields:
2003-06-02 11:19:24 +00:00
.Bl -tag -width indent
.It Ar size
2002-06-06 19:27:17 +00:00
An optional decimal digit string specifying the minimum field width.
2003-06-02 11:19:24 +00:00
.It Ar prec
2002-06-06 19:27:17 +00:00
An optional precision composed of a decimal point
.Sq Cm \&.
and a decimal digit string that indicates the maximum string length,
the number of digits to appear after the decimal point in floating point
output, or the minimum number of digits to appear in numeric output.
2003-06-02 11:19:24 +00:00
.It Ar fmt
2002-06-06 19:27:17 +00:00
An optional output format specifier which is one of
2003-06-02 11:19:24 +00:00
.Cm D , O , U , X , F ,
2002-06-06 19:27:17 +00:00
or
.Cm S .
These represent signed decimal output, octal output, unsigned decimal
output, hexadecimal output, floating point output, and string output,
respectively.
Some output formats do not apply to all fields.
2003-06-02 11:19:24 +00:00
Floating point output only applies to
.Vt timespec
fields (the
.Cm a , m ,
2002-06-06 19:27:17 +00:00
and
.Cm c
fields).
.Pp
The special output specifier
.Cm S
may be used to indicate that the output, if
applicable, should be in string format.
2003-06-02 11:19:24 +00:00
May be used in combination with:
.Bl -tag -width indent
2002-06-06 19:27:17 +00:00
.It Cm amc
2003-06-02 11:19:24 +00:00
Display date in
.Xr strftime 3
format.
2002-06-06 19:27:17 +00:00
.It Cm dr
Display actual device name.
.It Cm f
Display the flags of
.Ar file
as in
.Nm ls Fl lTdo .
2002-06-06 19:27:17 +00:00
.It Cm gu
Display group or user name.
.It Cm p
Display the mode of
.Ar file
as in
2003-06-02 11:19:24 +00:00
.Nm ls Fl lTd .
2002-06-06 19:27:17 +00:00
.It Cm N
Displays the name of
.Ar file .
.It Cm T
Displays the type of
.Ar file .
.It Cm Y
2003-06-02 11:19:24 +00:00
Insert a
.Dq Li " -\*[Gt] "
into the output.
Note that the default output format
2002-06-06 19:27:17 +00:00
for
.Cm Y
is a string, but if specified explicitly, these four characters are
prepended.
.El
2003-06-02 11:19:24 +00:00
.It Ar sub
An optional sub field specifier (high, middle, low).
Only applies to
2002-06-06 19:27:17 +00:00
the
2003-06-02 11:19:24 +00:00
.Cm p , d , r ,
2002-06-06 19:27:17 +00:00
and
.Cm T
output formats.
It can be one of the following:
2003-06-02 11:19:24 +00:00
.Bl -tag -width indent
2002-06-06 19:27:17 +00:00
.It Cm H
2003-06-02 11:19:24 +00:00
.Dq High
\[em]
specifies the major number for devices from
2002-06-06 19:27:17 +00:00
.Cm r
or
.Cm d ,
2003-06-02 11:19:24 +00:00
the
.Dq user
bits for permissions from the string form of
2002-06-06 19:27:17 +00:00
.Cm p ,
2003-06-02 11:19:24 +00:00
the file
.Dq type
bits from the numeric forms of
2002-06-06 19:27:17 +00:00
.Cm p ,
and the long output form of
.Cm T .
.It Cm L
2003-06-02 11:19:24 +00:00
.Dq Low
\[em]
specifies the minor number for devices from
2002-06-06 19:27:17 +00:00
.Cm r
or
.Cm d ,
2003-06-02 11:19:24 +00:00
the
.Dq other
bits for permissions from the string form of
2002-06-06 19:27:17 +00:00
.Cm p ,
2003-06-02 11:19:24 +00:00
the
.Dq user ,
.Dq group ,
and
.Dq other
bits from the numeric forms of
2002-06-06 19:27:17 +00:00
.Cm p ,
and the
2003-06-02 11:19:24 +00:00
.Nm ls Fl F
2002-06-06 19:27:17 +00:00
style output character for file type when used with
.Cm T
(the use of
.Cm L
for this is optional).
.It Cm M
2003-06-02 11:19:24 +00:00
.Dq Middle
\[em]
specifies the
.Dq group
bits for permissions from the
2002-06-06 19:27:17 +00:00
string output form of
.Cm p ,
2003-06-02 11:19:24 +00:00
or the
.Dq suid ,
.Dq sgid ,
and
.Dq sticky
bits for the numeric forms of
2002-06-06 19:27:17 +00:00
.Cm p .
.El
2003-06-02 11:19:24 +00:00
.It Ar datum
2002-06-06 19:27:17 +00:00
A required field specifier, being one of the following:
2003-06-02 11:19:24 +00:00
.Bl -tag -width indent
2002-06-06 19:27:17 +00:00
.It Cm d
Device upon which
.Ar file
resides.
.It Cm i
2003-06-02 11:19:24 +00:00
.Ar file Ns 's
2002-06-06 19:27:17 +00:00
inode number.
.It Cm p
File type and permissions.
.It Cm l
Number of hard links to
.Ar file .
.It Cm u , g
2003-06-02 11:19:24 +00:00
User ID and group ID of
.Ar file Ns 's
2002-06-06 19:27:17 +00:00
owner.
.It Cm r
Device number for character and block device special files.
.It Cm a , m , c , B
2002-06-06 19:27:17 +00:00
The time
.Ar file
was last accessed or modified, or when the inode was last changed, or
the birth time of the inode.
2002-06-06 19:27:17 +00:00
.It Cm z
The size of
.Ar file
in bytes.
.It Cm b
Number of blocks allocated for
.Ar file .
.It Cm k
Optimal file system I/O operation block size.
.It Cm f
User defined flags for
.Ar file .
.It Cm v
Inode generation number.
.El
.Pp
The following five field specifiers are not drawn directly from the
2003-06-02 11:19:24 +00:00
data in
.Vt "struct stat" ,
but are:
.Bl -tag -width indent
2002-06-06 19:27:17 +00:00
.It Cm N
The name of the file.
.It Cm R
The absolute pathname corresponding to the file.
2002-06-06 19:27:17 +00:00
.It Cm T
The file type, either as in
2003-06-02 11:19:24 +00:00
.Nm ls Fl F
or in a more descriptive form if the
.Ar sub
field specifier
2002-06-06 19:27:17 +00:00
.Cm H
is given.
.It Cm Y
The target of a symbolic link.
.It Cm Z
2003-06-02 11:19:24 +00:00
Expands to
.Dq major,minor
from the
.Va rdev
field for character or block
2002-06-06 19:27:17 +00:00
special devices and gives size output for all others.
.El
.El
.Pp
Only the
.Cm %
and the field specifier are required.
Most field specifiers default to
2002-06-06 19:27:17 +00:00
.Cm U
as an output form, with the
exception of
.Cm p
which defaults to
.Cm O ;
2002-06-06 19:27:17 +00:00
.Cm a , m ,
and
.Cm c
which default to
.Cm D ;
2002-06-06 19:27:17 +00:00
and
.Cm Y , T ,
and
2003-06-02 11:19:24 +00:00
.Cm N
2002-06-06 19:27:17 +00:00
which default to
.Cm S .
.Sh EXIT STATUS
2003-06-02 11:19:24 +00:00
.Ex -std stat readlink
2002-06-06 19:27:17 +00:00
.Sh EXAMPLES
If no options are specified, the default format is
"%d %i %Sp %l %Su %Sg %r %z \\"%Sa\\" \\"%Sm\\" \\"%Sc\\" \\"%SB\\" %k %b %#Xf %N".
.Bd -literal -offset indent
\*[Gt] stat /tmp/bar
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
.Ed
.Pp
2003-06-02 11:19:24 +00:00
Given a symbolic link
.Dq foo
2003-06-02 11:19:24 +00:00
that points from
.Pa /tmp/foo
to
.Pa / ,
you would use
2002-06-06 19:27:17 +00:00
.Nm
as follows:
.Bd -literal -offset indent
\*[Gt] stat -F /tmp/foo
lrwxrwxrwx 1 jschauma cs 1 Apr 24 16:37:28 2002 /tmp/foo@ -\*[Gt] /
\*[Gt] stat -LF /tmp/foo
drwxr-xr-x 16 root wheel 512 Apr 19 10:57:54 2002 /tmp/foo/
2002-06-06 19:27:17 +00:00
.Ed
.Pp
2003-06-02 11:19:24 +00:00
To initialize some shell variables, you could use the
2002-06-06 19:27:17 +00:00
.Fl s
flag as follows:
.Bd -literal -offset indent
\*[Gt] csh
% eval set `stat -s .cshrc`
% echo $st_size $st_mtimespec
1148 1015432481
\*[Gt] sh
$ eval $(stat -s .profile)
$ echo $st_size $st_mtimespec
1148 1015432481
.Ed
.Pp
In order to get a list of file types including files pointed to if the
2002-06-06 19:27:17 +00:00
file is a symbolic link, you could use the following format:
.Bd -literal -offset indent
$ stat -f "%N: %HT%SY" /tmp/*
/tmp/bar: Symbolic Link -\*[Gt] /tmp/foo
/tmp/output25568: Regular File
/tmp/blah: Directory
/tmp/foo: Symbolic Link -\*[Gt] /
.Ed
.Pp
In order to get a list of the devices, their types and the major and minor
device numbers, formatted with tabs and linebreaks, you could use the
following format:
.Bd -literal -offset indent
stat -f "Name: %N%n%tType: %HT%n%tMajor: %Hr%n%tMinor: %Lr%n%n" /dev/*
[...]
Name: /dev/wt8
Type: Block Device
Major: 3
Minor: 8
Name: /dev/zero
Type: Character Device
Major: 2
Minor: 12
.Ed
.Pp
In order to determine the permissions set on a file separately, you could use
the following format:
.Bd -literal -offset indent
\*[Gt] stat -f "%Sp -\*[Gt] owner=%SHp group=%SMp other=%SLp" .
drwxr-xr-x -\*[Gt] owner=rwx group=r-x other=r-x
.Ed
.Pp
In order to determine the three files that have been modified most recently,
you could use the following format:
.Bd -literal -offset indent
\*[Gt] stat -f "%m%t%Sm %N" /tmp/* | sort -rn | head -3 | cut -f2-
Apr 25 11:47:00 2002 /tmp/blah
Apr 25 10:36:34 2002 /tmp/bar
Apr 24 16:47:35 2002 /tmp/foo
.Ed
.Pp
To display a file's modification time:
.Bd -literal -offset indent
\*[Gt] stat -f %m /tmp/foo
1177697733
.Ed
.Pp
To display the same modification time in a readable format:
.Bd -literal -offset indent
\*[Gt] stat -f %Sm /tmp/foo
Apr 27 11:15:33 2007
.Ed
.Pp
To display the same modification time in a readable and sortable format:
.Bd -literal -offset indent
\*[Gt] stat -f %Sm -t %Y%m%d%H%M%S /tmp/foo
20070427111533
.Ed
.Pp
To display the same in UTC:
.Bd -literal -offset indent
\*[Gt] sh
$ TZ= stat -f %Sm -t %Y%m%d%H%M%S /tmp/foo
20070427181533
.Ed
2002-06-06 19:27:17 +00:00
.Sh SEE ALSO
.Xr file 1 ,
.Xr ls 1 ,
.Xr lstat 2 ,
.Xr readlink 2 ,
.Xr stat 2 ,
.Xr printf 3 ,
.Xr strftime 3
.Sh HISTORY
The
.Nm
utility appeared in
2005-03-28 04:02:45 +00:00
.Nx 1.6
and
2005-03-28 04:02:45 +00:00
.Fx 4.10 .
2002-06-06 19:27:17 +00:00
.Sh AUTHORS
2003-06-02 11:19:24 +00:00
.An -nosplit
2002-06-06 19:27:17 +00:00
The
.Nm
utility was written by
.An Andrew Brown
.Aq atatat@NetBSD.org .
This man page was written by
.An Jan Schaumann
.Aq jschauma@NetBSD.org .