stat — Detailed File and Filesystem Information

Display all metadata of a file with stat — size, permissions, owner, timestamps and inode, plus format strings and filesystem status.

stat shows every piece of a file's metadata at a glance – far more than ls -l: the exact size in bytes, permissions in both symbolic and octal form, owner and group, inode number, and the three timestamps for access (atime), modification (mtime) and status change (ctime). With the -c option and format strings such as %s, %a or %U you build the output exactly as a script needs it. Important: the syntax shown here applies to GNU stat from coreutils on Linux. On macOS and BSD the format switch is -f (instead of -c) and uses entirely different placeholders – there, -f is also not the filesystem status. On Linux, -f shows the filesystem status instead of file info.

Basic Usage

stat <file> — Show all available information about a file.

stat index.html

stat -f <filesystem> — Display filesystem status instead of file status.

stat -f /

stat -L <symlink> — Follow symlinks and show info about the target file.

stat -L /usr/bin/python3

stat <file1> <file2> — Show information for multiple files.

stat *.conf

Format Strings — File Info

stat -c '%s' <file> — Show file size in bytes.

stat -c '%s' backup.tar.gz

stat -c '%n %s' <file> — Show filename and size.

stat -c '%n %s' *.log

stat -c '%A' <file> — Show human-readable permissions (e.g., -rwxr-xr-x).

stat -c '%A' script.sh

stat -c '%a' <file> — Show permissions as octal number (e.g., 755).

stat -c '%a' /etc/passwd

stat -c '%U:%G' <file> — Show owner and group names.

stat -c '%U:%G' /var/log/syslog

stat -c '%F' <file> — Show file type (regular file, directory, symlink, etc.).

stat -c '%F' /dev/null

stat -c '%i' <file> — Show inode number.

stat -c '%i' myfile.txt

Format Strings — Timestamps

stat -c '%y' <file> — Show last modification time (human-readable).

stat -c '%y' config.yaml

stat -c '%x' <file> — Show last access time.

stat -c '%x' data.csv

stat -c '%z' <file> — Show last status change time (ctime).

stat -c '%z' /etc/hosts

stat -c '%w' <file> — Show file creation (birth) time if available.

stat -c '%w' readme.md

stat -c '%Y' <file> — Show modification time as Unix timestamp (seconds since epoch).

stat -c '%Y' deploy.log

Filesystem Info

stat -f -c '%T' <path> — Show filesystem type.

stat -f -c '%T' /

stat -f -c '%b %S' <path> — Show total blocks and block size.

stat -f -c '%b %S' /home

stat -f -c '%a' <path> — Show available blocks for unprivileged users.

stat -f -c '%a' /tmp

Common Patterns

stat -c '%a %n' * — List permissions of all files in current directory.

stat -c '%a %n' /etc/*.conf

stat -c '%s %n' * | sort -n — List files sorted by size.

stat -c '%s %n' *.log | sort -n

stat -c '%Y %n' * | sort -n | tail -5 — Show 5 most recently modified files.

stat -c '%Y %n' /var/log/* | sort -n | tail -5

stat -c '%U %n' * | grep -v root — Find files not owned by root.

stat -c '%U %n' /usr/local/bin/* | grep -v root

Conclusion

stat is your tool when ls -l does not tell you enough: exact bytes, all three timestamps and the inode at a glance. Its real strength shows with -c and format strings – with those you produce exactly the fields a script can process further, e.g. stat -c '%s %n' for a list sortable by size. When porting scripts, watch the platform: GNU stat uses -c with the placeholders shown here, whereas macOS/BSD use -f with a completely different format syntax – scripts meant to run on both must account for that (or use gstat from coreutils on macOS). For a quick overview reach for ls, for the content-based file type reach for file, and to change permissions reach for chmod.

Further Reading

  • ls – directory contents with permissions and size at a glance
  • file – determine the file type by content
  • chmod – change access permissions on files