stat Command
The stat command in Linux is used to display detailed information about a file or file system. This includes file size, permissions, ownership, timestamps (access, modify, change), and inode number. It's a valuable tool for system administrators and developers to inspect file metadata.
Syntax
Description
stat displays information about the given FILE(s). If FILE is a symbolic link, by default, stat displays information about the file the link points to. Use the -L option to display information about the link itself.
Common uses include:
- Viewing file permissions and ownership
- Checking file access, modification, and change times
- Retrieving inode numbers and device information
- Inspecting file system details (with
-foption)
Common Options
| Option | Description |
|---|---|
-L, --dereference |
Follow links |
-f, --file-system |
Display file system status instead of file status |
-c, --format=FORMAT |
Use the specified FORMAT instead of the default; interpret backslash escapes |
-t, --terse |
Print the information in terse form |
--printf=FORMAT |
Like --format, but interpret backslash escapes and do not output trailing newline |
Examples
Display file status
Displays detailed status information for 'myfile.txt'.
Display file system status
Displays status information about the file system where '/home/user' resides.
Display octal permissions
Displays the octal permissions of 'myfile.txt'.
Display file size and name
Displays the size and name of 'myfile.txt'.
Display modification time
Displays the last modification time of 'myfile.txt'.