🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

stat Command

Intermediate File Viewing & Searching man(1)

Display detailed file or filesystem status

👁 9 views 📅 Updated: Mar 15, 2026
SYNTAX
stat [OPTION]... FILE...

What Does stat Do?

The stat command displays detailed information about files and filesystems, including size, permissions, ownership, timestamps, inode number, and link count. It provides far more detail than ls.

stat shows three timestamps: access time (atime), modification time (mtime), and change time (ctime). mtime tracks content changes, ctime tracks metadata changes (permissions, ownership), and atime tracks when the file was last read.

stat is essential for debugging permission issues, understanding file metadata, checking inode numbers, and writing scripts that need precise file information.

Options & Flags

OptionDescriptionExample
-c Use custom format string for output stat -c '%s bytes, owner: %U' file.txt
-f Display filesystem information stat -f /
-L Follow symbolic links stat -L /usr/bin/python
-t Terse (machine-readable) output stat -t file.txt
%s Format: file size in bytes stat -c '%s' file.txt
%U/%G Format: owner/group name stat -c '%U:%G' file.txt
%a/%A Format: permissions (octal/human) stat -c '%a %A' file.txt

Practical Examples

#1 Full file information

Shows complete metadata including size, permissions, timestamps, and inode.
$ stat /etc/passwd

#2 Get file size in bytes

Outputs just the file size in bytes — useful in scripts.
$ stat -c '%s' largefile.iso
Output: 4294967296

#3 Show permissions in octal

Shows octal permissions and filename for security auditing.
$ stat -c '%a %n' /etc/shadow
Output: 640 /etc/shadow

#4 Show all timestamps

Displays all three timestamps in readable format.
$ stat -c 'Access: %x Modify: %y Change: %z' file.txt

#5 Filesystem information

Shows filesystem type, total/free space, block size, and inode info.
$ stat -f /

#6 Check inode number

Shows the inode number, useful for checking hard links.
$ stat -c '%i' file.txt
Output: 1234567

Tips & Best Practices

Useful format strings: Common formats: %s (size), %a (octal perms), %U (owner), %G (group), %y (mtime), %i (inode). Combine them: stat -c '%a %U %s %y' file
Three timestamps explained: mtime = content changed, ctime = metadata changed (permissions, owner), atime = file was read. ctime cannot be manually set.
ctime is not creation time: In Linux, ctime is change time (metadata change), NOT creation time. Birth time is only available on some filesystems (ext4: stat shows 'Birth').

Frequently Asked Questions

How do I see file permissions in octal format?
Use stat -c '%a' filename. This shows permissions like 644, 755, etc.
What is the difference between mtime and ctime?
mtime (modification time) changes when file content is modified. ctime (change time) changes when file metadata (permissions, ownership) is modified. ctime also changes when content changes.
How do I get the file size in a script?
Use stat -c '%s' filename to get the size in bytes. For human-readable size, use du -h filename or ls -lh filename.

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books →