Get Information About File Using stat Command on Linux

Get Information About File Using stat Command on Linux

The stat is a command line tool in the Linux operating system that allows users to obtain detailed information about a file or directory. This command provides a comprehensive set of attributes, such as file size, access permissions, timestamps, and much more. Whether you are a system administrator or developer, understanding how to use the stat command can prove immensely valuable for analyzing and managing files efficiently. This tutorial shows how to get information about file using stat command on Linux.

The basic syntax of the stat command is straightforward. Let’s take a look at the following example:

stat test.txt

The command output may look as follows:

  File: test.txt
  Size: 12                Blocks: 8          IO Block: 4096   regular file
Device: 10305h/66309d    Inode: 4866388     Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/     ubu)   Gid: ( 1000/     ubu)
Access: 2023-08-01 04:23:02.832870910 +0300
Modify: 2023-08-01 04:23:02.832870910 +0300
Change: 2023-08-01 04:23:02.832870910 +0300
 Birth: 2023-08-01 04:23:02.832870910 +0300

Let's break down the output of the command:

  • File - the output will start by displaying the path of the file for which the information is being retrieved.
  • Size - the output will show the size of the file in bytes.
  • Blocks - the number of allocated blocks the file takes. In our case, the file system allocates 8 blocks of data to store the content of test.txt.
  • IO Block - indicates the block size used by the file system for input/output operations.
  • File Type - indicates the type of the file (regular file in this case).
  • Device - indicates the device number (in hexadecimal and decimal) on which the file is stored. Each storage device on a Linux system is identified by a unique number.
  • Inode - displays the inode number assigned to the file. An inode is a data structure that stores metadata about the file, such as permissions, timestamps, and file location.
  • Links - represents the number of hard links associated with the file.
  • File Access Permissions - shows the file's access permissions in octal format (e.g. 0664) and in the symbolic form (e.g. -rw-rw-r--).
  • Uid - displays the User ID (UID) of the file owner. In this example, the UID is 1000, which corresponds to the user ubu.
  • Gid - shows the Group ID (GID) of the file's group. Here, the GID is also 1000, corresponding to the group ubu.
  • Access - indicates the last time the file was accessed (read, written, or executed).
  • Modify - shows the last time the content of the file was modified.
  • Change - represents the last time the file's metadata (permissions, owner, etc.) was changed.
  • Birth - indicates the file's creation time. Note that the availability of the birth time depends on the file system and operating system support.

Leave a Comment

Cancel reply

Your email address will not be published.