Statistics command tutorial to view data in detail

stat It is a command-line utility that displays detailed information about files that are passed as arguments or system files.

This article describes how to use the stat command.

Using commands stat

Grammar for orders stat They are as follows:

stat [OPTION]... FILE...

stat Accepts one or more entry names FILE It includes a number of options that control command and output behavior.

Let’s look at an example:

stat file.txt

The output will look like this:

  File: file.txt
  Size: 4030      	Blocks: 8          IO Block: 4096   regular file
Device: 801h/2049d	Inode: 13633379    Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/   linuxize)   Gid: ( 1000/   linuxize)
Access: 2019-11-06 09:52:17.991878701 +0100
Modify: 2019-11-06 09:52:17.971878714 +0100
Change: 2019-11-06 09:52:17.971878714 +0100
 Birth: -

When connected without options, stat It will display the information from the file as follows:

  • Files – File name.
  • Size – The file size in bytes.
  • Lumps – Number of custom blocks the file retrieves.
  • IO Block – Size in bytes per block.
  • file type – (such as regular files, directories, symbolic links …)
  • Device – The device number is in hexadecimal and decimal.
  • The anode – Inode number.
  • Links – The number of hard links.
  • being able to – File permissions by digital and symbolic methods
  • Uid Username and owner name.
  • good – Group ID and owner name.
  • Context – SELinux Security Context.
  • being able to – The last time the file was accessed.
  • Modify – The last time the file content was changed.
  • They change – The last time a file’s attributes or contents were changed.
  • Birth – File creation time (not supported on Linux).
See also  Git behind office proxy

Displays information about the file system

To get information about the file system where the specified file is located, instead of information about the file itself, use -f, (--file-system):

stat -f file.txt

The command output will look like this:

  File: "package.json"
    ID: 8eb56097b4564d20 Namelen: 255     Type: ext2/ext3
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 61371211   Free: 24595668   Available: 22365251
Inodes: Total: 15645336   Free: 13899610

when stat Called with options -f, stat The following information will appear:

  • Files – File name.
  • ID – The file system identifier in hexadecimal.
  • Namlin – The maximum length of the file name.
  • Primary block size – The size of each block in the file system.
  • Lumps:
    • sum – The total number of blocks in the file system.
    • Free – The number of blocks available in the file system.
    • Available – Number of blocks available for non-root users.
  • INODS:
    • sum – Total number of inodes in the file system.
    • Free – Number of inodes available in the file system.

Symbolic links (follow)

By default, stat Do not follow symbolic links. If you run a command on the symbolic link, the output will include information about the symbolic link, not the file it refers to:

stat /etc/resolv.conf
  File: /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
  Size: 39        	Blocks: 0          IO Block: 4096   symbolic link
Device: 801h/2049d	Inode: 8122259     Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-11-06 21:12:26.834956073 +0100
Modify: 2019-08-14 12:11:48.122354519 +0200
Change: 2019-08-14 12:11:48.122354519 +0200
 Birth: -


To unmark (follow) the symbolic link and display information about the file that the symbolic link is pointing to, use an extension -L, (--dereference):

stat -L /etc/resolv.conf
  File: /etc/resolv.conf
  Size: 715       	Blocks: 8          IO Block: 4096   regular file
Device: 17h/23d	Inode: 989         Links: 1
Access: (0644/-rw-r--r--)  Uid: (  101/systemd-resolve)   Gid: (  103/systemd-resolve)
Access: 2019-11-06 21:12:26.834956073 +0100
Modify: 2019-08-14 12:11:48.122354519 +0200
Change: 2019-08-14 12:11:48.122354519 +0200
 Birth: -

Customize the output

Command stat It has two options that allow you to customize the output to suit your needs: -c, (--format="format") And the --printf="format".

The difference between these two options is when two or more files are used as parameters --format Automatically adds a new line after each parameter output. --Printf Interpretation of backslash escape.

See also  Learn about Command id in Linux

There are several file formats and file systems directives that you can use with --format And the --printf.

For example, to see only the file types you’ll use:

stat --format="%F" /dev/null
character special file

You can combine any number of formatting directions and optionally use a custom separator between them. The separator can be a single character or a string:

stat --format="%n,%F" /dev/null
/dev/null,character special file

To interpret special characters such as new lines or tabs, use the options --printf:

stat --printf="Name: %nnPermissions: %an" /etc

n Type a new line:

Name: /etc
Permissions: 755

Stat Information can also be presented in a short form. This format is useful for analysis by other utilities.

Activate the command with options -t (--terse) To print the output in short form:

stat -t /etc
/etc 12288 24 41ed 0 0 801 8134465 147 0 0 1543063333 1543063333 1543063333 0 4096

For a complete list of all formatting directives for files and file systems, type man stat or stat --help In your Linux distribution station.


The stat command prints information about the specified file and system details.

In Linux, there are many other commands that can display information about a specific file, with the ls Most used, but it only shows partial, not complete information like that provided by the command stat.

Source link

Originally posted 2020-11-18 19:18:00.

About wahyuway

Check Also

How to install and configure Anaconda on CentOS 7

How to install and configure Anaconda on CentOS 7

Anaconda is the most popular machine learning and data science tool used in large scale …

Leave a Reply