Linux stat Command
Linux stat
Command
The stat
command in Linux is used to display detailed information about files and file systems. It provides access, modify, change, and birth timestamps along with metadata like file size, permissions, and ownership. This makes it useful for both system administrators and forensic analysts.
Basic Syntax
The general syntax of the command are as follows:
$ stat [options] filename
Examples
View File Information
$ stat file.txt
Shows detailed information about file.txt
, including size, permissions, owner, and timestamps.
Display Only File Size
$ stat -c %s file.txt
Outputs the file size in bytes.
Show Last Access Time
$ stat -c %x file.txt
Displays the last access timestamp of the file.
Show Last Modification Time
$ stat -c %y file.txt
Displays the last time the file content was modified.
Show Last Change Time
$ stat -c %z file.txt
Shows the last time file metadata (permissions, ownership, etc.) changed.
Custom Output Format
$ stat -c "File: %n | Size: %s bytes | Modified: %y" file.txt
Displays a custom summary of file details in one line.
Key Timestamps
Timestamp | Description |
---|---|
Access | Last time the file was read. |
Modify | Last time the file content was modified. |
Change | Last time file metadata (permissions/ownership) changed. |
Birth | File creation time (may not be available on all filesystems). |
The stat
command is a versatile utility for examining files in Linux. Whether you are troubleshooting file issues, monitoring file activity, or conducting forensic analysis, stat
provides detailed and structured insights into file metadata and timestamps.