Stat command in Linux with examples
Last Updated :
08 Sep, 2024
The 'stat' command is an invaluable tool in the Linux command suite, providing detailed statistics about files and file systems. It displays crucial information such as file size, permissions, ownership, and timestamps, making it an essential utility for system administrators and power users.
What is the 'stat' command?
'stat' serves as a versatile utility that fetches and displays data about files and directories. From determining file types to monitoring file system usage, 'stat' helps users gain insights into various file attributes which are crucial for system management and file handling operations.
Syntax:
The basic syntax of using stat command is as follows:
stat --options filenames
Stat can accept one or more filenames as an input to the stat command. Now let's see one example
stat /etc/resolv.conf
Output:

Detailed File Information
When executed, 'stat' provides a wealth of information about each specified file:
- File: The name of the provided file. If the provided file is a symlink, then the name will be different.
- Size: The size of a given file in Bytes.
- Blocks: Total number of allocated blocks to the file to store on the hard disk.
- IO Block: The size of every allocated block in bytes.
- File type: The file may be of the following types: Regular files, special files, directories, or symbolic links.
- Device: Device number in hexadecimal format.
- Inode: Inode number of the file.
- Links: Number of hard links of the file.
- Access: Access permissions in the numeric and symbolic methods.
- Context: The field stores SELinux security context.
- Access: The last time at which the file was accessed.
- Modify: The last time at which file was modified.
- Change: The last time the at which file’s attribute or content was changed.
- Birth: The time at which the file was created.
Now let's see how can we display information about the file system.
Displaying the File System Information
stat command can provide the file system information when we provide file name with the -f (--file-system) options. Syntax of using the -f option with the stat command:
stat -f filename
Here is one example of the -f option :

We can also provide the directory or file system as an input to the stat command as follows:
stat -f /

The information we get for the filesystem from the stat
- File: The name of provided file.
- ID: File system ID in hexadecimal format.
- Namelen: The maximum length (number of characters) of a file name.
- Fundamental block size: Total size of each block on the file system.
- Blocks:
- Total: Total number of blocks in the file system
- Free: Total number of free blocks in the file system
- Available: Total number of free blocks available for non-root users
- Inodes:
- Total: Total number of inodes in the file system.
- Free: Total number of free inodes in the file system.
Using Stat With Multiple File
To get the information about multiple files using the stat command, just mention the filenames separated by space:
stat locale.conf login.defs
This will show the information about the mentioned files.

Dereference Symlinks
If we provide the symbolic link file to the stat command, then it will give the information about the symbolic link instead of the original file. Here is one example:

Now let's see how we can dereference Symlinks. To follow or dereference the symbolic and display information about the file of which the symbolic like point stat provide -L (--dereference) option. We can use this option to dereference the symbolic links. Here Example:
stat -L /etc/localtime
The output will be like this:

We can see that stat is showing information about the /bin folder.
Customizing the Output
stat provides us the option to customize output instead of using the default output format. There are two ways by which we can customize the output
The first is using the '-c' option or the '--format' option with the format of the output. If we provide the multiple files to the stat command with the '--format' option, then it will automatically add the new line after each operand's output:
stat --format='%n' /etc/passwd

Another way to print customized output is using the '--print' option with the format. With this option, we can provide trailing characters to the format for example if we want to add a new line after each line output we can use '\n' trailing characters with a backslash. Here is one of using '--print' option
stat --print='%n\n' /etc/passwd

To know all format sequences, read the man page of the stat using the man command. The stat can also display the information in the terse form. We can display information in the terse form with '-terse' option:
stat -t /etc/passwd

Understanding the Timestamps
Timestamps show the information about the timezone. Generally, the timestamps show the time at which the file was created from the UTC timezone. if the value is positive, then the file was created ahead of the UTC timezone and if the value is negative then the file is created before the UTC timezone.
For example:

In the above example, the value of the timestamp is +0530 which means the file is created 5 hours 30 minutes ahead of UTC time. Here is one note for stat command, your shell may have its own version of the stat. To know about your shell stat read the man page using the man command:
man stat

Conclusion
The 'stat' command is a powerful tool for Linux users needing detailed file and file system information. Its versatility in handling multiple files, customizable outputs, and comprehensive display of attributes makes it indispensable for effective file management and system administration tasks.
Similar Reads
Linux Commands Cheat Sheet Linux, often associated with being a complex operating system primarily used by developers, may not necessarily fit that description entirely. While it can initially appear challenging for beginners, once you immerse yourself in the Linux world, you may find it difficult to return to your previous W
13 min read
grep command in Unix/Linux The grep command in Unix/Linux is a powerful tool used for searching and manipulating text patterns within files. Its name is derived from the ed (editor) command g/re/p (globally search for a regular expression and print matching lines), which reflects its core functionality. grep is widely used by
7 min read
Linux/Unix Tutorial Linux is one of the most widely used open-source operating systems. It's fast, secure, stable, and powers everything from smartphones and servers to cloud platforms and IoT devices. Linux is especially popular among developers, system administrators, and DevOps professionals.Linux is:A Unix-like OS
10 min read
25 Basic Linux Commands For Beginners [2025] While performing a task, we all need shortcuts. Shortcuts help us to complete a task quickly. Linux comes with such commands which are one to two words, using that commands, you can perform several operations in no time. As a beginner, you must be aware of those basic Linux commands to complete an o
13 min read
Sed Command in Linux/Unix With Examples The SED command is one of the most powerful commands used during the process of text processing in Linux/Unix operating systems. The SED command is typically invoked for executing operations such as replace and search, text manipulation, and stream editing.With SED, you can manipulate text files wit
9 min read
AWK command in Unix/Linux with examples Awk is a scripting language used for manipulating data and generating reports. The awk command programming language requires no compiling and allows the user to use variables, numeric functions, string functions, and logical operators. Awk is a utility that enables a programmer to write tiny but eff
8 min read
How to Find a File in Linux | Find Command The find command in Linux is used to search for files and directories based on name, type, size, date, or other conditions. It scans the specified directory and its sub directories to locate files matching the given criteria.find command uses are:Search based on modification time (e.g., files edited
9 min read
Introduction to Linux Shell and Shell Scripting If we are using any major operating system, we are indirectly interacting with the shell. While running Ubuntu, Linux Mint, or any other Linux distribution, we are interacting with the shell by using the terminal. In this article we will discuss Linux shells and shell scripting so before understandi
8 min read
ZIP command in Linux with examples In Linux, the zip command compresses one or more files or directories into a single.zip archive file. This saves disk space, keeps data organized, and makes it simple to share or backup files. It's among the most used compression utilities, particularly when sharing large files via email or storing
6 min read
screen command in Linux with Examples The screen command is an advanced terminal multiplexer that allows you to have multiple sessions within one terminal window. It's like having "tabs" in your Linux terminal â you can open, detach, switch, or resume sessions at any time without losing what you're working on. It's particularly convenie
7 min read