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

JavaScript implements H5 gold coin function (example code)

Today I made a Spring Festival gold coin red enve...

4 Ways to Quickly Teach Yourself Linux Commands

If you want to become a Linux master, then master...

Dealing with the problem of notes details turning gray on web pages

1. In IE, if relative positioning is used, that is...

10 ways to view compressed file contents in Linux (summary)

Generally speaking, when we view the contents of ...

JavaScript immediate execution function usage analysis

We know that in general, a function must be calle...

Continuous delivery using Jenkins and Docker under Docker

1. What is Continuous Delivery The software produ...

MySQL 5.7.12 installation and configuration tutorial under Mac OS 10.11

How to install and configure MySQL on Mac OS 10.1...

5 Reasons Why Responsive Web Design Isn’t Worth It

This article is from Tom Ewer's Managewp blog,...

4 Scanning Tools for the Linux Desktop

While the paperless world has not yet emerged, mo...

Understanding MySQL clustered indexes and how clustered indexes grow

In this note, we briefly describe What is the B+T...

Introduction to Linux common hard disk management commands

Table of contents 1. df command 2. du command 3. ...

Play mp3 or flash player code on the web page

Copy code The code is as follows: <object id=&...

js to achieve sliding carousel effect

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

How to bind domain name to nginx service

Configure multiple servers in nginx.conf: When pr...

How to use Linux tr command

01. Command Overview The tr command can replace, ...