stat
Overview
The stat command displays detailed information about files or file systems. It shows file attributes such as size, permissions, timestamps, inode information, and more.
Syntax
stat [options] file...Common Options
| Option | Description |
|---|---|
-f |
Display file system status instead of file status |
-L |
Follow links (show information about the linked file) |
-c FORMAT |
Use custom format for output |
--printf=FORMAT |
Like -c, but interpret backslash escapes |
-t |
Print information in terse form |
--format=FORMAT |
Use specified FORMAT instead of default |
Key Use Cases
- View detailed file metadata and timestamps
- Check file system information
- Get inode information
- Format output for scripting
- Check file permissions and ownership details
Examples with Explanations
Example 1: Basic Usage
stat filename.txtShows complete information about filename.txt including size, permissions, timestamps, and inode details.
Example 2: Custom Format
stat -c "%n %s %y" filename.txtShows only the filename (%n), size (%s), and last modification time (%y).
Example 3: File System Information
stat -f /homeDisplays information about the file system containing /home.
Understanding Output
The default output includes: - File name and type - Size in bytes - Block size and blocks allocated - Device ID and Inode number - Links count - Access permissions - UID/GID - Access time (atime) - Modification time (mtime) - Change time (ctime) - Birth time (if available)
Common Usage Patterns
- Use
-fwhen you need file system information - Use
-cwith format strings for scripting - Use
-Lwhen working with symbolic links - Combine with
findfor batch file information
Performance Analysis
- Minimal system impact for single files
- Can be resource-intensive when used with many files
- Consider using
ls -lfor basic information when full details aren’t needed