In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to use the stat command in Linux. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Linux stat command
We can think of the stat command as a better version of the ls-l command. Although the-l flag provides more detailed information about the file, such as file ownership and permissions, the stat command is more in-depth and provides rich information about the file.
The syntax of the Linux stat command is as follows:
$stat [option] file name
1. Stat command with no parameters
The stat command displays the default output in its simplest form without any parameters. This includes file size and type, device type, inode number, UID, GID, number of links, and file access / modification date.
For example, to view the details of the files in the current home directory, execute:
Linuxmi@linuxmi:~/www.linuxmi.com$ stat www.linuxmi.com.py
Let's introduce the specific meaning of the output:
File: displays the file name.
Size: file size in bytes.
Blocks: the number of blocks allocated to the file.
IO block: this is the byte size of each block.
Equipment: device number, hexadecimal or decimal format.
Inode: this is the index node number of the file.
Links: the number of hard links associated with the file.
Access rights: file permissions in symbolic or digital format.
Uid: the user ID and name of the owner.
Gid: group ID and owner name.
Context: SeLinux security context
File type: displays the type of file (regular file, symbolic link, etc.).
Access: displays the time when the file was last accessed.
Modify: displays when the contents of the file were last changed.
Change: displays when the file metadata, such as permissions and ownership, was last changed.
2. View multiple file information
You can view detailed reports on multiple files by specifying the files on the command line in turn, as shown below.
Linuxmi@linuxmi:~/www.linuxmi.com$ stat linuxmi.cpp linuxmi.py
3. Display the file system status
You can use the-f option to check the status of the file system where the file resides, as shown below. This gives the block size, total memory, and available memory, with just a few attributes.
Linuxmi@linuxmi:~/www.linuxmi.com$ stat-f / home
4. Display information in a concise form
The t option is used to display information in a concise format, as follows:
Linuxmi@linuxmi:~/www.linuxmi.com$ stat-t linuxmi.cpp
5. Enable the following of symbolic links
In general, if you run the stat command on a symbolic link, it will only provide you with information about the link, not the file that the link points to. Take the / usr/share/zoneinfo/America/Cayman symbolic link as an example.
Linuxmi@linuxmi:~/www.linuxmi.com$ stat / usr/share/zoneinfo/America/Cayman
In the above example, the symbolic link / usr/share/zoneinfo/America/Cayman points to-> Panama. Symbolic links are only 6 bytes long.
To get information about the file that the link points to, use the-L option (also known as the dereferencing option).
Linuxmi@linuxmi:~/www.linuxmi.com$ stat-L / usr/share/zoneinfo/America/Cayman
This now displays information about the file instead of the link, even if the output indicates that it is a link. This is because we pass it as a parameter through the stat command.
6. Format sorting
From the previous example, we have seen the stat command print out a series of information on the terminal. If you need specific information, you can use a format sequence to customize the output to provide exactly what you want and to retain other details.
Common expressions for custom output include the-printf or-format options
For example, to display only the Inode of a file, use the% I format sequence, as shown below. The\ noperation prints a new production line.
Linuxmi@linuxmi:~/www.linuxmi.com$ stat-- printf='%i\ n 'linuxmi.cpp
To display access rights and uid (user ID), use the an and u format sequences.
Linuxmi@linuxmi:~/www.linuxmi.com$ stat-- printf='%a:%u\ n 'linuxmi.cpp
The-format option prints out a new line without additional action.
Linuxmi@linuxmi:~/www.linuxmi.com$ stat-format='%a:%F' linuxmi.cpp
The following is a complete list of format sequences that you can use:
% a displays access permissions in octal format.
% A displays access permissions in an easy-to-read format.
% b this is the number of allocated blocks (see% B).
% B byte size of each block reported by% b.
% C displays the SELinux security context string.
D displays the device number in decimal format.
% D device number in hexadecimal format.
% f displays the original mode in hexadecimal.
% F displays the file type.
% g prints the owner's group ID.
% G prints the owner's group name.
H shows the number of hard links.
% I prints out the index node number.
% m prints the installation point.
N display the file name of the file
% N displays the file name with a signed reference and unreferences if a symbolic link is used
% o prints the best Istroke O transfer size prompt.
The total size of s in bytes.
T main device type (hexadecimal) for character / block device special files
% T secondary device type (hexadecimal) for character / block device special files
% u displays the owner's user ID.
% U prints the user name of the owner.
% w shows the generation time of the file, which is easy to read;-if unknown.
% W the time when the print file was born, the number of seconds after the era, or 0 if unknown.
% x the time of the last visit, which is easy for us to understand.
The time of X's last visit, the number of seconds since the era.
% y shows the last time it was last modified, making it easy to read.
% Y prints the number of seconds since the era when it was last modified.
% z this is the time of the last change, which humans can understand.
The time when Z was last changed, the number of seconds since the era.
7. Get help with the stat command
For more command options, use the-help option and the stat command
Linuxmi@linuxmi:~/www.linuxmi.com$ stat-help
You can also access the man page of the stat command and run
Linuxmi@linuxmi:~/www.linuxmi.com$ man stat
8. Check the stat version
Finally, check the version of the stat command and run the command:
Linuxmi@linuxmi:~/www.linuxmi.com$ stat-version
This is the end of the article on "how to use stat commands in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.