stat Command Cheat Sheet
stat displays file or file system status. It provides much more detail than ls -l.
Synopsis
stat [OPTION]... FILE...
Basic Usage
File Info
stat file.txt
file.txt
- Size: 1024
- Blocks: 8
- IO Block: 4096
- Type: regular file
- Device: 802h/2050d
- Inode: 123456
- Links: 1
- Access/Modify/Change timestamps
Custom Formatting (-c / --format)
Show only Octal Permissions
Useful for scripts checking permissions.
stat -c "%a" file.txt
# Output: 644
Show User and Group Name
stat -c "%U %G" file.txt
# Output: root root
Show File Size in Bytes
stat -c "%s" file.txt
# Output: 1024
Show Combined Info
stat -c "File: %n, Size: %s bytes, Perms: %a" file.txt
File System Status (-f)
Display info about the file system where the file resides, not the file itself.
stat -f /
ext2/ext3
- Block size
- Total/Free blocks (Disk usage)
- Inodes
Follow Symlinks (-L)
By default, stat shows info about the link itself. Use -L to see info about the target file.
stat -L /usr/bin/python
Common Format Sequences
| Sequence | Description |
|---|---|
%a |
Access rights in octal (e.g., 644) |
%A |
Access rights in human readable (e.g., -rw-r--r--) |
%n |
File name |
%s |
Total size, in bytes |
%U |
User name of owner |
%G |
Group name of owner |
%x |
Time of last access |
%y |
Time of last modification |
%z |
Time of last change |
%i |
Inode number |
Notes
- Timestamps:
- Access (atime): Last read using
cat,grep, etc. - Modify (mtime): Content was modified.
- Change (ctime): Meta-data change (permissions, owner).
- Access (atime): Last read using