Use of Linux stat command

Use of Linux stat command

1. Command Introduction

The stat command is used to display detailed information about a file or file system. When displaying file information, it is more detailed than the ls command.

2. Command format

stat [OPTION]... FILE..

3. Command Options

-L, --dereference: follow the symbolic link to resolve the original file instead of the symbolic link;
-f, --file-system: Display the file system information instead of the file information;
-c, --format=FORMAT: Output in the specified format instead of the default format;
	The available format control characters for displaying file information are as follows:
	%a: Display access permissions in octal %A: Display access permissions in readable form %b: Display the number of occupied blocks %B: Display the number of bytes occupied by each block %C: SELinux security context string
	%d: Displays the device number where the file is located in decimal format %D: Displays the device number where the file is located in hexadecimal format %f: Displays the file type in hexadecimal format %F: File type. File types under Linux are mainly divided into ordinary files, directories, character device files, block device files, symbolic link files, sockets, etc. %g: file owner group ID
	%G: file owner group name %h: file hard link number %i: inode number %m: mount point of the disk partition where the file is located, such as /data
	%n: file name %N: file name enclosed in single quotes. If it is a soft link, the file name it points to is also displayed %o: optimal I/O transfer size hint
	%s: actual file size, in bytes %t: major device type in hex, for character/block device special files
	%T:minor device type in hex, for character/block device special files
	%u: Owner user ID
	%U: Owner user name %w: File creation time, output - means it cannot be known %W: File creation time, output Unix timestamp, 0 means it cannot be known %x: Output the last access time atime in readable form
	%X: Unix timestamp output last access time atime
	%y: Output the last modification time mtime in readable form
	%Y: Unix timestamp output after modification time mtime
	%z: Output the last status change time ctime in readable form
	%Z: Unix timestamp output last status change time ctime
	
	The available format control characters for displaying file system information are:
	%a: Number of free blocks available to non-super users %b: Total number of blocks in the file system %c: Total number of file nodes in the file system %d: Number of available file nodes %f: Number of available file blocks %i: Hexadecimal file system ID
	%l: Maximum file name length %n: File name %s: Size of a block, in bytes (for faster transfers)
	%S: The basic size of a block, in bytes (used to count the number of blocks)
	%t: Output the file system type in hexadecimal format %T: Output the file system type in readable form --printf=FORMAT: Output in the specified format instead of the default format. Similar to --format, but can interpret backslash escape characters, such as newline characters \n;
-t, --terse: concise mode output, only display summary information;
--help: Display help information;
--version: Display version information.

4. Common Examples

(1) Display file information.

[root@TENCENT64 ~]# stat Changelog
 File: 'Changelog'
 Size: 1598 Blocks: 8 IO Blocks: 4096 regular file
Device: fd01h/64769d Inode: 1579435 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-11-06 22:39:54.110931887 +0800
Modify: 2018-11-06 22:39:54.110931887 +0800
Change: 2018-11-06 23:07:14.428548887 +0800
 Birth: -

Information Explanation:

File: 'Changelog': The file name is Changelog
Size: 1598: File size 1598 bytes
Blocks: 8: The number of blocks occupied by the file
IO Block: 4096:
regular file: file type (ordinary file)
Device: fd01h/64769d: The device number where the file is located, displayed in hexadecimal and decimal respectively.
Inode: 1579435: file node number
Links: 1: Number of hard links
Access: (0644/-rw-r--r--): Access rights
Uid: Owner ID and name
Gid: Owner user group ID and name
Access: Last access time
Modify: Last modified time
Change: Last status change time
Birth -: Unable to get the file creation time. Note: File creation time is not stored in Linux files

(2) Display the file system information where the file is located.

[root@TENCENT64 /data/vas_pgg_proj/apps/penguin_game]# stat -f Makefile
 File: "Makefile"
  ID: 6f75a4f02634e23e Namelen: 255 Type: ext2/ext3
Block size: 4096 Fundamental block size: 4096
Blocks: Total: 43830967 Free: 30155578 Available: 27923259
Inodes: Total: 11162880 Free: 11077199

Information Explanation:

File: "Makefile": The file name is "Makefile";
ID: 6f75a4f02634e23e: File system ID
Namelen: 255: Maximum file name length
Type: ext2/ext3: File system type name
Block size: 4096: The block size is 4096 bytes
Fundamental block size: 4096: The basic block size is 4096 bytes
Blocks: Total: 43830967 Free: 30155578 Available: 27923259:
Inodes: Total: 11162880 Free: 11077199

The above is the detailed content of the use of Linux stat command. For more information about Linux stat command, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Use of Linux gzip command
  • Usage of Linux userdel command
  • Use of Linux date command
  • How to run Linux commands in the background
  • Use of Linux ls command
  • Use of Linux ln command
  • Linux cut command explained
  • Use of Linux bzip2 command

<<:  Node.js+express message board function implementation example

>>:  How to create a table by month in MySQL stored procedure

Recommend

Docker builds CMS on-demand system with player function

Table of contents text 1. Prepare the machine 2. ...

MySQL 5.7 installation and configuration tutorial

This article shares the MySQL installation and co...

MySQL online log library migration example

Let me tell you about a recent case. A game log l...

Docker container orchestration implementation process analysis

In actual development or production environments,...

CSS Tricks to Create Wave Effects

It has always been very difficult to achieve wave...

Solution to the problem of saving format in HTML TextArea

The format of textarea can be saved to the databas...

Native js to achieve simple carousel effect

This article shares the specific code of js to ac...

Mysql Workbench query mysql database method

Mysql Workbench is an open source database client...

IE conditional comments for XHTML

<br />Conditional comments are a feature uni...

Install tomcat and deploy the website under Linux (recommended)

Install jdk: Oracle official download https://www...

Vue uses canvas to realize image compression upload

This article shares the specific code of Vue usin...

How to install vncserver in Ubuntu 20.04

Ubuntu 20.04 has been officially released in Apri...