How to Use the Linux stat Command to View File and System Status

When you need to view the properties of a file in Linux, the standard approach is to run the ls -l command. This provides a quick overview, showing the file’s owner, read/write permissions, size in bytes, and the date it was last modified. However, the Linux file system tracks much more metadata than ls can display. If a system administrator needs to know exactly when a file was accessed, what its numerical inode is on the hard drive, or the specific block size of the underlying file system, they must use the stat command. The stat command extracts and displays the comprehensive status of a file or a file system, presenting all available metadata in an easy-to-read list.

Basic File Status Output

Using stat is straightforward; simply provide the path to the file or directory you want to inspect.

  1. Open your terminal.
  2. Type the command followed by the filename: stat /etc/passwd
  3. Press Enter.

The terminal will output a block of detailed information containing several critical fields:

  • File: The absolute or relative path to the file.
  • Size: The total size in bytes.
  • Blocks: The number of hard drive blocks allocated to store the file.
  • IO Block: The size of every block (typically 4096 bytes).
  • Inode: The unique index number assigned to the file by the file system (crucial for finding hard links).
  • Links: The number of hard links pointing to this inode.
  • Access (Permissions): Displays the permissions in both the standard octal format (e.g., 0644) and the symbolic format (e.g., -rw-r--r--).
  • Uid & Gid: The numerical ID and the text name of the user and group who own the file.

Understanding the Three Timestamps (MAC times)

Perhaps the most useful feature of stat is its display of the three distinct timestamps associated with every Linux file, often referred to as MAC times. The standard ls -l command only shows the Modification time, but stat reveals all three down to the fraction of a second:

  • Access (atime): The exact time the file was last opened and read by a user or a program (e.g., viewing it with the cat command).
  • Modify (mtime): The exact time the contents of the file were last changed (e.g., editing the text and saving it).
  • Change (ctime): The exact time the metadata of the file was last altered (e.g., changing the file permissions with chmod or changing the owner with chown).

Checking File System Status

In addition to checking individual files, the stat command can be used to check the health and configuration of the entire file system (the partition) where a specific file resides. You do this by using the -f (file system) flag.

stat -f /

Running this command against the root directory (/) will output the file system type (e.g., ext4 or btrfs), the maximum length a filename can be (usually 255 characters), and detailed statistics on exactly how many total data blocks and inodes exist on the drive versus how many are currently free and available for use.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.