stat
All file metadata — permissions, owner, size, inode, timestamps — in the format you need
stat shows file metadata from the inode: type, permissions, owner, size, link count, all timestamps. With -c it prints only the fields you need in a given format — more reliable than cutting columns out of ls -l. With -f it shows file system information. The sandbox has GNU coreutils 9.4.
Syntax
stat [options] file…
stat -c 'format' file…
stat -f [-c 'format'] path…
Exit code: 0 — all files found, 1 — at least one is missing.
Default output
File: f
Size: 6 Blocks: 8 IO Block: 4096 regular file
Device: 0,64 Inode: 1134952 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2026-10-13 15:21:52.594726010 +0000
Modify: 2026-10-13 15:21:52.594726010 +0000
Change: 2026-10-13 15:21:52.594726010 +0000
Birth: 2026-10-13 15:21:52.594726010 +0000
| Field | Meaning |
|---|---|
Size | size in bytes (for a symlink — the length of the target path) |
Blocks | how many 512-byte blocks are actually used on disk |
IO Block | recommended I/O block size |
| type | regular file, directory, symbolic link, fifo, socket, character special file… |
Device | number of the device the file lives on |
Inode / Links | inode number / number of hard links |
Access: (0644/-rw-r--r--) | permissions in octal and symbolic form |
Uid / Gid | numeric ID and name of the owner / group |
Access / Modify / Change | atime (read), mtime (content), ctime (metadata) |
Birth | creation time (- if the FS doesn't store it) |
Options
| Option | What it does |
|---|---|
-c 'format' | print according to the format, with a newline at the end |
--printf='format' | the same, but no trailing newline, and \n, \t are understood |
-L | for a symbolic link, show the target's data, not the link's |
-f | data about the file system the path lives on |
-t | everything on one line (terse machine format) |
-c format: file
| Code | What it prints | Example |
|---|---|---|
%n | file name | f |
%N | quoted name, for a link — with its target | 'l' -> 'f' |
%a | permissions in octal (%#a — with a leading zero) | 644, 4755 |
%A | permissions in symbolic form with the type | -rw-r--r-- |
%f | "raw" mode in hex | 81a4 |
%F | file type in words | regular file |
%U / %u | owner name / UID | root / 0 |
%G / %g | group name / GID | root / 0 |
%s | size in bytes | 6 |
%b / %B | number of blocks / block size in bytes for %b | 8 / 512 |
%i | inode number | 1134952 |
%h | number of hard links | 1 |
%d / %D | device number (decimal / hex) | 64 |
%m | mount point | / |
%o | recommended I/O block size | 4096 |
%x / %X | atime: human-readable / Unix seconds | 2026-10-13 15:21:52.59… +0000 / 1791904912 |
%y / %Y | mtime: human-readable / Unix seconds | |
%z / %Z | ctime: human-readable / Unix seconds | |
%w / %W | creation time: human-readable (- if unknown) / seconds (0) | |
%t / %T | major / minor device number (hex) — for /dev/* | 1 / 3 for /dev/null |
%C | SELinux context |
Width and precision work as in printf: %10s — right-align to 10 characters, %-6s — left-align, %.19y — date without fractional seconds (2026-10-13 15:21:58), %.3Y — seconds with milliseconds.
-c format with -f: file system
| Code | What it prints |
|---|---|
%T | FS type in words (ext2/ext3, tmpfs, overlayfs…) |
%b | total data blocks |
%f / %a | free blocks / available to a regular user |
%S | block size for these counters |
%c / %d | total inodes / free inodes |
%l | maximum file name length |
%n | path name |
Examples
# permissions in octal — for comparison in a script
stat -c '%a' /etc/shadow
# permissions, owner, group on one line
stat -c '%A %U:%G %n' /etc/passwd /etc/shadow
# size in bytes
stat -c %s backup.tar.gz
# modification time in seconds — handy for computing age
echo $(( $(date +%s) - $(stat -c %Y app.log) ))
# modification date without nanoseconds
stat -c '%.19y' app.log
# a "name — size" table via --printf
stat --printf '%n\t%s\n' *.log
# the link target's data, not the link's
stat -L /etc/localtime
# FS type and free inodes
stat -f -c 'type=%T free inodes=%d' /
Pitfalls
-cdoesn't understand\tand\n:stat -c '%n\t%s'prints\tliterally. For control characters use--printf(and then write the trailing\nyourself).- By default a link means the link itself.
stat linkshowssymbolic link, permissions777and size = path length. For the target —-L. %adoesn't pad with zeros: afterchmod 755you get755, afterchmod 4755—4755. For uniform width —%#a(0755) or%04a.%Yvs%y. For arithmetic use seconds (%Y); the human-readable%ycontains nanoseconds and the time zone.%wis often-. Not every FS stores the creation time, and not every tool copies it.- This is GNU syntax. On macOS/BSD
stathas different flags (-f '%Lp'); scripts usingstat -cdon't work there.