How to Use stat Command on Linux – Guide

The stat command provides information about the file and the file system. The stat command can provide information such as file size, access permissions and user and group ID, birth time of file access. The stat command has another function that can also be used to provide file system information. This is the best tool when we need the information of any file.

Check Linux file status

$ stat /var/log/syslog Size: 536870912 bytes (524 MB) Blocks: 24576 (2.4 KB each) IO blocks: 4096 (4 KB) File type: Linux syslog file Inode value: 6144064 (6144 bytes) Number of links: 1 ..

/var/log/syslog Size: 26572 Blocks: 56 I/O Block: 4096 regular fileDevice: 80ah/2058d Inode: 8129076 Links: 1Access: (0640/-rw-r—–) Uid: ( 104 / syslog) Gid: (4/ adm) Access: 2018-04-06 09:42:10.987615337 +0530Modify: 2018-04-06 11:09:29.756650149 +0530Change

Check the file system status

To display the file system status instead of the file status, use the -f option. ..

This command prints the contents of the syslog file in the current directory.

This filesystem was created on ext2/ext3 partition with size of 255 GB. ..

The Bitcoin network is designed to have a block size of 4096 bytes. ..

Blocks: 84769790 free, 16012830 available

Inodes are a type of file that stores data. The total number of inodes is 21544960, and the free number is 20995459.

You can supply a directory/filesystem as an argument, as shown.

Linux supports links, which means that certain files may have one or more links. This can be useful for keeping related files together, or for making it easier to access a file from multiple locations. ..

To enable stat to follow links, use the -L flag as shown.

This command displays the following information: -L: List of files -c: Creation time -m: Modification time stat -L / This command displays the following information: -L: List of files -c: Creation time -m: Modification time ..

/dev/sda1: 4096 blocks, 8 IO blocks, 4096 devices, 80ah/2058d inode, 2 links

Use a custom format to display information

Stat allows you to use a specific or custom format instead of the default. The -c flag is used to specify the format used, prints a newline after each use of the format string. ..

The printf() function allows you to print text to the console, but it also has a –printf option that allows you to disable printing of a newline. This can be useful if you want to print text with backslash escape sequences, which is not allowed by default. ..

This command prints the current user’s name and the number of days since last login.

The file “example.txt” has a format string of “%d %b %Y”. This means that the file was created on January 1, 2016, at 12:00 PM. ..

%L – last login time %G – game name %A – active players %P – players online ..

The owner group name for this company is “G”.

The %C variable stores the security context string for the process. ..

Last status change time is 12:00 PM.

The example below shows how to use the accepted format strings for file systems. ..

$ stat –printf=’%nn%an%bn’ /var/log/stat.log

The meaning of format strings used in the above command is not known.

%n – show the name of the file

The %a command prints a list of free blocks available to non-superusers. ..

The b command displays the total blocks of data in the file system. ..

The -t option can be used to print the information concisely.

This command prints the contents of the syslog file on the system.

syslog: -12760: The system is in the process of logging a message. -32: The number of messages in the syslog stream. -81a0: A new message has been added to the syslog stream. -104: The number of messages in the current log file. -80a8129076: A new message has been added to the 80a8129076 log file.

Your shell may have its own version of the stat command, which may support different output formats than the default command. To see all supported output format strings, see the stat man page. ..

Final note

Stat Command is a powerful command line tool that can be used to gather information about your computer. This guide will show you how to use stat command to gather information about your computer, including CPU, memory, disk space, and network usage. ..