Linux Command – stat

Command Overview

stat is a powerful command in Linux used to view detailed status information about files or file systems. It is more comprehensive than ls -l, and its output includes, but is not limited to: file size, permissions, owner, last access/modify/status change time, inode number, and device information.

Usage

The syntax of the stat command is as follows

stat [options] file/directory/symbolic_link # options are optional

Common options and descriptions for the stat command are as follows

 -L,--dereference: follow symbolic links -f,--file-system: display file system status instead of file status -t,--terse: output information in a concise manner -c,--format=FORMAT: customize output format (supports format specifiers) --help: display help information for the command --version: display version information for the command

Command Case Scenarios

1. Default output: View complete file status (no options)

[root@blog ~]# stat anaconda-ks.cfg  File: anaconda-ks.cfg  Size: 1505            Blocks: 8          IO Block: 4096   Regular file Device: fd00h/64768d      Inode: 67478510    Hard links: 1Permissions: (0600/-rw-------)  Uid: (    0/    root)   Gid: (    0/    root)Context: system_u:object_r:admin_home_t:s0Last access: 2025-05-29 21:30:49.502452114 +0800Last change: 2025-05-29 21:30:49.622455612 +0800Last modification: 2025-05-29 21:30:49.622455612 +0800Creation time: 2025-05-29 21:30:49.502452114 +0800

2. View information for multiple files

[root@blog ~]# stat anaconda-ks.cfg /etc/yum.repos.d/redhat.repo # can accept multiple arguments and display information for each file sequentially.  File: anaconda-ks.cfg  Size: 1505            Blocks: 8          IO Block: 4096   Regular file Device: fd00h/64768d      Inode: 67478510    Hard links: 1Permissions: (0600/-rw-------)  Uid: (    0/    root)   Gid: (    0/    root)Context: system_u:object_r:admin_home_t:s0Last access: 2025-05-29 21:30:49.502452114 +0800Last change: 2025-05-29 21:30:49.622455612 +0800Last modification: 2025-05-29 21:30:49.622455612 +0800Creation time: 2025-05-29 21:30:49.502452114 +0800  File: /etc/yum.repos.d/redhat.repo  Size: 358             Blocks: 8          IO Block: 4096   Regular file Device: fd00h/64768d      Inode: 69108248    Hard links: 1Permissions: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)Context: system_u:object_r:system_conf_t:s0Last access: 2025-05-30 11:50:13.236899775 +0800Last change: 2025-05-30 11:50:13.235899733 +0800Last modification: 2025-05-30 11:50:13.235899733 +0800Creation time: 2025-05-30 11:50:13.235899733 +0800

3. View file system status (instead of a single file)

[root@blog ~]# stat -f /home # use -f option to display the status of the file system where the file is located, rather than the file itself.  File: "/home"    ID: fd0000000000 Filename length: 255     Type: xfsBlock size: 4096       Fundamental block size: 4096    Blocks: Total: 10469376   Free: 9259897    Available: 9259897Inodes: Total: 20971520   Free: 20838518# output will include file system information such as Type, Block size, Total blocks, Free blocks, etc. This is useful for quickly checking disk usage.

4. Concise output

[root@blog ~]# stat -t anaconda-ks.cfganaconda-ks.cfg 1505 8 8180 0 0 fd00 67478510 1 0 0 1748525449 1748525449 1748525449 1748525449 4096 system_u:object_r:admin_home_t:s0# outputs fields in a fixed order for easier script parsing

5. Custom format output

Using --printf or -c option allows customizing the output format and content. Format specifier examples:   %n: filename   %s: file size (bytes)   %U: owner username   %G: group name   %i: inode number   %A: permissions (symbolic format, e.g., -rw-r--r--)   %a: permissions (octal numeric format, e.g., 644)   %x,%y,%z,%w: represent access time (atime), modification time (mtime), status change time (ctime), creation time (btime)   %F: file type (e.g., "regular file", "directory") Application examples: #1) Show only filename and size: [root@blog ~]# stat -c "File: %n Size: %s bytes" anaconda-ks.cfgFile: anaconda-ks.cfg Size: 1505 bytes
#2) Show only inode number (commonly used for debugging hard links): [root@blog ~]# stat -c %i  anaconda-ks.cfg67478510
#3) Display modification time in a more readable format: [root@blog ~]# stat -c "The last modification time of this file is: %y" anaconda-ks.cfgThe last modification time of this file is: 2025-05-29 21:30:49.622455612 +0800
#4) Batch view permissions and owners of multiple files: [root@blog ~]# stat -c "%A %U %G %n" *.cfg  # this command will list the permissions, owners, group, and filename of all .cfg files in the current directory-rw------- root root anaconda-ks.cfg

6. Track symbolic links (default dereference)

# By default, stat will track symbolic links and display information about the target file. [root@blog ~]# stat /var/mail  File: /var/mail -> spool/mail  Size: 10              Blocks: 0          IO Block: 4096   Symbolic link Device: fd00h/64768d      Inode: 101618387   Hard links: 1Permissions: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)Context: system_u:object_r:mail_spool_t:s0Last access: 2025-09-12 09:34:28.921770355 +0800Last change: 2024-06-25 22:28:11.000000000 +0800Last modification: 2025-05-29 21:25:12.135806195 +0800Creation time: 2025-05-29 21:25:12.128806007 +0800
# If you want to view information about the symbolic link itself (such as size, timestamps), rather than its target, you need to use -L or --dereference option to disable tracking.[root@blog ~]# stat -L /var/mail  File: /var/mail  Size: 18              Blocks: 0          IO Block: 4096   Directory Device: fd00h/64768d      Inode: 33896061    Hard links: 2Permissions: (0775/drwxrwxr-x)  Uid: (    0/    root)   Gid: (   12/    mail)Context: system_u:object_r:mail_spool_t:s0Last access: 2025-05-29 21:30:51.521510955 +0800Last change: 2025-05-29 21:30:18.434546704 +0800Last modification: 2025-05-29 21:30:18.434546704 +0800Creation time: 2025-05-29 21:25:12.129806033 +0800

Notes

  1. Make good use of the Tab key for auto-completion: When entering paths, pressing the Tab key can automatically complete directory or file names, avoiding spelling errors and improving efficiency.
  2. View the complete manual by using man stat

Recommended Reading

1. Linux Series Articles

Installing RHEL8.x Operating System

Installing RHEL9.x Operating System

Simple Configuration of RHEL9.X

For more content, click on the public account homepage to view

2. Linux Commands

Collection of Linux Commands

If you have any technical points or content you would like to see

You can leave a message below to tell the author

Click the lower left corner “Read the original“, to receive benefits and mirror download links.

Leave a Comment