stat Command in Linux: Display File and Filesystem Information

Sometimes ls -l does not tell you enough about a file. You may need its inode number, the exact time its permissions changed, or its size in bytes for a script. The stat command prints all of the metadata the filesystem keeps for a file, including its size, inode, permissions, owner, and timestamps. The command takes its name from stat(), the system call that returns this information.
This guide explains how to use the stat command, read its output, and customize it for scripts.
stat Command Syntax
The syntax for the stat command is as follows:
stat [OPTION]... FILE...stat accepts one or more input FILE names and includes a number of options that control the command behavior and output.
Displaying File Information
Here is an example of running stat on a regular file:
stat file.txtThe output will look something like this:
File: file.txt
Size: 3600 Blocks: 8 IO Block: 4096 regular file
Device: 253,1 Inode: 262163 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/linuxize) Gid: ( 1000/linuxize)
Access: 2026-11-18 21:45:32.653465123 +0000
Modify: 2026-11-18 21:45:32.654679667 +0000
Change: 2026-11-18 21:45:32.654679667 +0000
Birth: 2026-11-18 21:45:32.653465123 +0000When invoked without any options, stat displays the following file information:
- File - The name of the file.
- Size - The size of the file in bytes.
- Blocks - The number of 512-byte blocks allocated to the file.
- IO Block - The preferred block size for I/O operations, in bytes.
- File type - For example: regular file, directory, or symbolic link.
- Device - The device number as major,minor in decimal. GNU coreutils releases older than 9.0 print it in hex and decimal, for example
801h/2049d. - Inode - The inode number.
- Links - Number of hard links.
- Access - File permissions in numeric and symbolic form.
- Uid - User ID and name of the owner .
- Gid - Group ID and name of the owning group.
- Context - The SELinux security context (shown only on SELinux-enabled systems).
- Access - The last time the file was accessed.
- Modify - The last time the file’s content was modified.
- Change - The last time the file’s attributes or content changed.
- Birth - File creation time. It requires Linux kernel 4.11 or later, GNU coreutils 8.32 or later, and a filesystem that records it (ext4, btrfs, xfs). Otherwise, it shows
-.
To learn more about file timestamps and how to update them, see the touch command guide .
stat comes from uutils coreutils, a Rust rewrite of the GNU tools. In uutils 0.8.0, the size label is lowercase (size:), so stat file | grep Size finds nothing. This was fixed in uutils 0.10.0
, which prints Size:. Symlink names on the File: line are quoted. Use stat -c %s file to get the size without parsing labels, or run the GNU version as gnustat.Displaying Filesystem Information
To get information about the filesystem where the given file resides, instead of information about the file itself, use the -f (--file-system) option:
stat -f file.txtThe output of the command will look like this:
File: "file.txt"
ID: 7e9f9a745a795e20 Namelen: 255 Type: ext2/ext3
Block size: 4096 Fundamental block size: 4096
Blocks: Total: 7344672 Free: 5745842 Available: 5741746
Inodes: Total: 3801088 Free: 3622133When stat is invoked with the -f option, it shows the following information:
- File - The name of the file.
- ID - Filesystem ID in hex.
- Namelen - Maximum length of file names.
- Type - The filesystem type. On ext4, it shows
ext2/ext3. The three filesystems share the same magic number. - Block size - The preferred block size for I/O transfers.
- Fundamental block size - The size of the blocks counted in the
Blocksline. - Blocks:
- Total - Number of total blocks in the filesystem.
- Free - Number of free blocks in the filesystem.
- Available - Number of free blocks available to non-root users.
- Inodes:
- Total - Number of total inodes in the filesystem.
- Free - Number of free inodes in the filesystem.
Dereference (Follow) Symlinks
By default, stat does not follow symlinks
. If you run the command on a symlink, the output will include information about the symlink, not the file it points to:
stat /etc/resolv.conf File: /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
Size: 39 Blocks: 0 IO Block: 4096 symbolic link
Device: 253,1 Inode: 1418 Links: 1
Access: (0777/lrwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2026-11-18 21:44:54.654000001 +0000
Modify: 2026-09-18 16:31:30.948499834 +0000
Change: 2026-09-18 16:42:01.455208687 +0000
Birth: 2026-09-18 16:42:01.455208687 +0000The File: line shows where the link points. The size of 39 bytes is the length of the target path, not the size of the target file.
To dereference (follow) the symlink and display information about the file it points to, use the -L (--dereference) option:
stat -L /etc/resolv.conf File: /etc/resolv.conf
Size: 920 Blocks: 8 IO Block: 4096 regular file
Device: 0,30 Inode: 1157 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 989/systemd-resolve) Gid: ( 989/systemd-resolve)
Access: 2026-11-18 21:45:08.149019993 +0000
Modify: 2026-11-18 21:44:54.016794543 +0000
Change: 2026-11-18 21:44:54.016794543 +0000
Birth: 2026-11-18 21:44:54.016789751 +0000This time, the output describes the target file. It is a regular file of 920 bytes, owned by systemd-resolve.
Customizing the Output
The stat command has two options that allow you to customize the output: -c (--format="format") and --printf="format".
The two options differ in how they handle escapes and newlines. --format prints a newline after the output for each file and prints backslash escapes such as \n literally. --printf interprets backslash escapes and does not add a trailing newline.
Here are the most commonly used format directives:
| Directive | Description |
|---|---|
%n | File name |
%s | Total size in bytes |
%b | Number of blocks allocated |
%A | Permissions in human-readable form |
%a | Permissions in octal |
%U | User name of owner |
%G | Group name of owner |
%i | Inode number |
%h | Number of hard links |
%F | File type |
%y | Time of last modification (human-readable) |
%Y | Time of last modification, seconds since the Epoch |
%x | Time of last access (human-readable) |
%z | Time of last status change (human-readable) |
%w | Time of file birth (human-readable, - if unknown) |
%W | Time of file birth, seconds since the Epoch (0 if unknown) |
For example, to view only the type of the file, you would run:
stat --format="%F" /dev/nullcharacter special fileYou can combine any number of format directives and optionally use custom separators:
stat --format="%n,%F" /dev/null/dev/null,character special fileTo interpret special characters like newline or tab, use the --printf option:
stat --printf='Name: %n\nPermissions: %a\n' /etc\n prints a new line:
Name: /etc
Permissions: 755The stat command can also display information in terse form, which is useful for parsing by other utilities. Use the -t (--terse) option:
stat -t /etc/etc 12288 24 41ed 0 0 fd01 40 150 0 0 1790279687 1790279725 1790279725 1789749533 4096The fields always come in the same order: name, size, blocks, raw mode in hex, UID, GID, device number in hex, inode, number of links, and the major and minor device type. They are followed by the access, modify, change, and birth times in seconds since the Epoch, and the I/O block size. On SELinux systems, the security context is added at the end.
For a complete list of all format directives, run man stat or stat --help.
stat syntax on Linux. On BSD/macOS systems, stat uses different flags and format options.Using stat in Scripts
Each format directive prints a single value. You can use stat -c in shell scripts without parsing the default output.
To store the size of a file in a variable, run:
size=$(stat -c %s file.txt)You can compare the value in an if statement
. The following snippet prints a message when a log file grows past 100 MiB:
if [ "$(stat -c %s app.log)" -gt 104857600 ]; then
echo "app.log is larger than 100 MiB"
fiThe %Y directive prints the modification time in seconds since the Epoch. You can subtract it from the current time to get the age of a file in seconds:
echo $(( $(date +%s) - $(stat -c %Y backup.tar.gz) ))7200The file was last modified 7200 seconds (two hours) ago. The date +%s part prints the current time in the same format. See the date command guide
for more format options.
To check the permissions and ownership of several files at once, pass them all to a single stat command:
stat -c '%a %U:%G %n' /etc/passwd /etc/shadow /etc/sudoers644 root:root /etc/passwd
640 root:shadow /etc/shadow
440 root:root /etc/sudoersEach line shows the octal permissions, the owner and group, and the file name.
To find out whether two file names point to the same file, compare their inode numbers with %i:
stat -c '%i %h %n' file.txt file-link.txt262163 2 file.txt
262163 2 file-link.txtBoth names have the same inode (262163) and a link count of 2. They are hard links
to the same data. Inode numbers are unique only within one filesystem. If you compare files on different filesystems, add %d to check the device numbers too.
Quick Reference
| Command | Description |
|---|---|
stat file | Display file information |
stat -f file | Display filesystem information |
stat -L file | Follow symlinks |
stat -t file | Terse output for parsing |
stat --format="%F" file | Show file type only |
stat --format="%s" file | Show file size in bytes |
stat --format="%A %U %n" file | Show permissions, owner, and name |
stat -c '%Y' file | Show modification time in seconds since the Epoch |
stat -c '%a %U:%G %n' file... | Show permissions and owner of several files |
stat --printf='%n\t%s\n' file | Custom output with tab separator |
Troubleshooting
Birth time shows -
The filesystem does not record creation time, or your system is too old to read it. Birth time needs Linux kernel 4.11 or later and GNU coreutils 8.32 or later. Ubuntu 20.04 ships coreutils 8.30 and shows - for every file. Birth time is stored on ext4, btrfs, xfs, and tmpfs. Check your filesystem type with df -T /path.
Access time does not change after reading a file
Most Linux systems mount filesystems with the relatime option. With relatime, the kernel updates the access time only when the stored value is older than or equal to the modify or change time, or more than 24 hours old. Check the mount options with findmnt -no OPTIONS /.
Context field is missing from output
The Context (SELinux) field only appears on SELinux-enabled systems. On standard Ubuntu or Debian systems it will not be shown.
Output fields differ between systems
The exact output depends on the coreutils version, kernel version, filesystem type, and whether SELinux is active. GNU coreutils releases older than 9.0 print the device number in hex. The uutils 0.8.0 release prints size: in lowercase, while 0.10.0 prints Size:.
stat: cannot statx ‘file’: No such file or directory
The path does not exist. Check the spelling and your current directory. GNU coreutils has used this wording on Linux builds with statx support since version 8.32. Builds without statx support print cannot stat. The uutils version on Ubuntu 26.04 also prints cannot stat and adds (os error 2) at the end.
FAQ
What is the difference between stat and ls?ls
shows a summary of file information suitable for listing directories. stat shows the complete low-level metadata for a single file, including inode number, block count, and all three timestamps.
How do I show only the file size with stat?
Use stat --format="%s" filename. This prints the size in bytes. To get a human-readable logical size, use du --apparent-size -sh filename
. Without --apparent-size, du reports allocated disk space.
Why does the Birth time show -?
The filesystem does not store creation time, or the system is too old to read it. Filesystems such as ext4, btrfs, and xfs record birth time. stat can read it on Linux kernel 4.11 or later with GNU coreutils 8.32 or later. Older filesystems like ext2/ext3 do not support it.
How do I use stat in a script to get a file’s permissions?
Use stat --format="%a" filename for octal permissions or stat --format="%A" filename for the symbolic form. These are easy to assign to a variable: perms=$(stat --format="%a" file).
What is the difference between Modify time and Change time?
Modify time (mtime) changes when the file’s content is written. Change time (ctime) changes when content or metadata (permissions, ownership, links) changes. See the touch command guide
for how to update these timestamps.
Conclusion
The stat command prints detailed information about given files and file systems. In Linux, several other commands can display file information, with ls
being the most used one, but it shows only a subset of the information provided by stat. For filesystem usage summaries, see the df command guide
.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page