Examples
Common -c format fields:
| Field | Meaning |
|---|---|
%n |
name |
%s |
size in bytes |
%A / %a |
permissions (rwx / octal) |
%U / %G |
owner / group |
%y / %Y |
mtime (human-readable / unix) |
%i |
inode number |
%h |
number of hard links |
Full file information — size, permissions, owner, timestamps (atime/mtime/ctime), inode.
stat file
everything
stat -c '%a %U:%G %n' file
permissions-owner-name
stat -c '%Y' file
mtime (unix)
ls -lc file
ctime instead of mtime
stat shows a file's metadata, which ls doesn't show: exact
timestamps, inode, link count, permissions in octal, owner and group.
Indispensable when working out "why doesn't the service read this file"
or "when was this changed". By default, stat on a symlink shows the
link's own metadata, not the metadata of the file it points to — the -L
flag is needed for the target's metadata.
The -c flag sets a custom output format via placeholders (%a, %U,
%s, and others) — without it, stat prints a fixed multi-line block
that's inconvenient to parse in scripts. -L (--dereference) switches
the output from the link itself to the file it points to; without it,
checking permissions with stat on a symlink shows the link's
permissions (usually 777), not the file's.
| Option | What it does | Example |
|---|---|---|
-c --format FORMAT |
Custom output format using placeholders (%a, %U, %s, and more). | stat -c '%a %U:%G %n' file |
-L --dereference |
Show metadata for the file a symlink points to, not the link itself. | stat -L file |
-f --file-system |
Show file-system information instead of file metadata. | stat -f -c '%T' / |
--printf FORMAT |
Like --format, but without an automatic trailing newline. | stat --printf='%n %s байт\n' *.log |
-t --terse |
Terse single-line output — convenient to parse with awk or cut. | stat -t file |
Nothing found. Try a shorter query.
Common -c format fields:
| Field | Meaning |
|---|---|
%n |
name |
%s |
size in bytes |
%A / %a |
permissions (rwx / octal) |
%U / %G |
owner / group |
%y / %Y |
mtime (human-readable / unix) |
%i |
inode number |
%h |
number of hard links |
%x) — last access (read). Often disabled (noatime) for
speed.%y) — last content change. This is what ls -l shows.%z) — last metadata change (permissions, owner,
rename).The file was rewritten (an editor saves in place) or a process appended
to it. ctime shows whether permissions/owner were touched separately
from the content.
ls -l shows a large size but no space is usedA sparse file. Compare stat -c '%s' (logical size) with %b×%B
(blocks actually allocated) — see also disk-usage.
Symlinks on Linux almost always show 777 — these permissions don't
affect access to the target, which is checked on the target file itself.
View them with stat -L file, not stat file.
Found an inaccuracy? Report an error in the article