Table of Contents
This tip is about the how to Use stat Command on Linux. So read this free guide, How to Use stat Command on Linux. If you have query related to same article you may contact us.
How to Use stat Command on Linux – Guide
stat is a command that provides information about the file and the file system. The stat command provides information such as file size, access permissions and user and group ID, birth time of file access. The stat command has another function that can also be used to provide file system information. This is the best tool when we need the information of any file.
Check Linux file status
The easiest way to use stat is to provide a file as an argument. The following command will display the size, blocks, IO blocks, file type, inode value, number of links and much more information about the /var/log/syslog file as shown in the screenshot:
Check the file system status
In the previous example, the stat command treated the input file as a normal file, however, to display the file system status instead of the file status, use the -f option.
You can also supply a directory/filesystem as an argument, as shown.
Enable symlink tracking
As Linux supports links (symbolic and hard links), certain files may have one or more links, or may even exist in a file system.
To enable stat to follow links, use the -L flag as shown.
Use a custom format to display information
4. stat also allows you to use a specific or custom format instead of the default. The -c flag is used to specify the format used, prints a newline after each use of the format string.
Alternatively, you can use the –printf option which allows parsing backslash escape sequences and disables printing a trailing newline. You need to use n in the format to print a newline, for example.
Meaning of format strings for files used in the above example:
Here is an example that shows the use of accepted format strings for file systems.
Meaning of format strings used in the above command.
Print information in concise form
The -t option can be used to print the information concisely.
As a last note, your shell may have its own version of stat, see your shell’s documentation for details on the options it supports. To see all supported output format strings, see the stat man page.
Final note
I hope you like the guide How to Use stat Command on Linux. In case if you have any query regards this article you may ask us. Also, please share your love by sharing this article with your friends.