stat Command in Linux: Display File and Filesystem Information

stat is a command-line utility that displays detailed information about given files or file systems.
This article explains how to use the stat command.
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: 4030 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 13633379 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ linuxize) Gid: ( 1000/ linuxize)
Access: 2019-11-06 09:52:17.991979701 +0100
Modify: 2019-11-06 09:52:17.971979713 +0100
Change: 2019-11-06 09:52:17.971979713 +0100
Birth: -When 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 allocated blocks the file takes.
- IO Block — The size in bytes of every block.
- File type — For example: regular file, directory, or symbolic link.
- Device — Device number in hex and decimal.
- Inode — 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. Supported on Linux kernel 4.11 and later on filesystems that record it (ext4, btrfs, xfs). Shows
-when the filesystem does not store birth time.
To learn more about file timestamps and how to update them, see the touch command guide .
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: "package.json"
ID: 8eb53097b4494d20 Namelen: 255 Type: ext2/ext3
Block size: 4096 Fundamental block size: 4096
Blocks: Total: 61271111 Free: 25395668 Available: 22265851
Inodes: Total: 15630336 Free: 13979610When 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.
- Fundamental block size — The size of each block on the filesystem.
- 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: 801h/2049d Inode: 8126659 Links: 1
Access: (0777/lrwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-11-06 21:12:26.875956073 +0100
Modify: 2018-07-24 11:11:48.128794519 +0200
Change: 2018-07-24 11:11:48.128794519 +0200
Birth: -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: 715 Blocks: 8 IO Block: 4096 regular file
Device: 17h/23d Inode: 989 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 101/systemd-resolve) Gid: ( 103/systemd-resolve)
Access: 2019-11-06 20:35:25.603689619 +0100
Modify: 2019-11-06 20:35:25.555689733 +0100
Change: 2019-11-06 20:35:25.555689733 +0100
Birth: -Customizing the Output
The stat command has two options that allow you to customize the output: -c (--format="format") and --printf="format".
The difference between these two options is that when two or more files are used as operands, --format automatically adds a newline after each file’s output, while --printf interprets backslash escapes.
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 |
%F | File type |
%y | Time of last modification (human-readable) |
%x | Time of last access (human-readable) |
%z | Time of last status change (human-readable) |
%w | Time of file birth (human-readable) |
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 801 8126465 147 0 0 1573068933 1573068927 1573068927 0 4096For 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.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 --printf='%n\t%s\n' file | Custom output with tab separator |
Troubleshooting
Birth time shows -
The filesystem does not record creation time, or the kernel is older than 4.11. Birth time is stored on ext4, btrfs, xfs, and tmpfs. Check your filesystem type with df -T /path.
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 kernel version, filesystem type, and whether SELinux is active. Fields like Birth and Context may not appear on all systems.
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 size, use du -sh
instead.
Why does the Birth time show -?
The filesystem does not store creation time. Filesystems such as ext4, btrfs, and xfs do record birth time on Linux kernel 4.11 and 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
.
If you have any questions or feedback, feel free to leave a comment below.
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 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page