Linux System stat Instruction usage

Source: Internet
Author: User
Tags chmod echo command touch command

Stat Instructions: File/File system details are displayed.

The stat command is primarily used to display detailed information about a file or file system, which has the following syntax:

Stat command-to display the details of the file, including Inode, Atime, Mtime, CTime

Applicable scenarios:

You can use the Stat command to view information such as Atime,mtime,ctime in a file or directory, or you can use the LS command, but Stat also sees information such as the device number, environment, and so on.

Note:

1) Stat Common output:

2) Use the LS command for viewing atime,mtime,ctime:

3) A few notes of the STAT command:

-F does not display information about the file itself and displays information about the file system where the file resides

-L Display Symbolic links

-C File Permissions

-T compact mode, displaying only summary information

In fact, the stat command displays the I node information for the file. The Linux file system stores information in blocks, and each file is indexed with the I node in order to find the location of the storage space where the file resides.

The so-called I node, which is a data structure for file system management, is a 64-byte long table that contains all the information necessary to describe the file, including the size, type, access rights, and owner of the file

Querying information for RC.D files

[[Email protected] rc.d]# stat rc0.d///can clearly analyze the information of a file or directory
File: ' rc0.d/'
size:4096 blocks:8 IO block:4096 Directory
device:fd00h/64768d inode:1309217 Links:2
Access: (0755/drwxr-xr-x) Uid: (0/root) Gid: (0/root)
Access:2014-06-26 21:02:26.776082938 +0800
modify:2014-06-12 15:16:57.848087079 +0800
change:2014-06-12 15:16:57.848087079 +0800

[[email protected] rc0.d]# du-sh//All files in this directory are 4K and the same size as above
4.0K.

To inquire about the file system where the Ec.d file is located:

[[email protected] rc.d]# stat-f rc0.d///This display is the same as the current system file system information, because rc.0 is in the current system's file system
File: "Rc0.d/"
id:303116b72802c784 namelen:255 TYPE:EXT2/EXT3
Block size:4096 fundamental block size:4096
blocks:total:7558388 free:5545748 available:5161800
inodes:total:1921360 free:1850717

You can also view your hard disk's information

[Email protected] rc.d]# STAT/DEV/SDA
File: '/dev/sda '
size:0 blocks:0 IO block:4096 Block Special File
device:5h/5d inode:6308 links:1 Device type:8,0
Access: (0660/BRW-RW----) Uid: (0/root) Gid: (6/disk)
Access:2014-06-27 20:57:07.213940088 +0800
Modify:2014-06-27 20:57:05.037938949 +0800
Change:2014-06-27 20:57:05.037938949 +0800

SDA hard disk File system Information

[Email protected] rc.d]# stat-f/DEV/SDA
File: "/DEV/SDA"
id:0 namelen:255 Type:tmpfs
Block size:4096 fundamental block size:4096
blocks:total:61793 free:61734 available:61734
inodes:total:61793 free:61080

Three times shown using the stat command under Linux

#1. [Email protected] tmp]# stat 1.txt

File: ' 1.txt '
Size:8 blocks:8 IO block:4096 Regular file
device:802h/2050d inode:196617 links:1
Access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root)
access:2013-10-20 21:43:54.000000000 +0800
modify:2013-10-20 21:35:42.000000000 +0800
change:2013-10-20 21:35:42.000000000 +0800

#2. Stat shows the contents of the Inode--inode contains the meta-information of the file, specifically the following:
* Number of bytes in the file
* User ID of the owner of the file
* The group ID of the file
* file read, write, execute permissions
* The timestamp of the file, a total of three
* Number of links, that is, how many filenames point to this inode
* Location of File data block

#3. IO BLOCK: The size of the logical block is 4,096 bytes
Blocks: The physical minimum block is 512, and IO block is 4096, so this takes up 8 physical blocks.
Access:atime
Modify:mtime, modify the time, note that this is not the settling time, m not the meaning of make
Change:ctime, change the time.

#4. How to query the three time by LS?
LS-LC filename Lists the CTime of the file
Ls-lu filename Lists the atime of the file
ls-l filename Lists the mtime of the file--ll This is the time that is displayed by default

#5. These three times are bad differences, but must be distinguished, because many applications will take into account these times, such as when doing a synchronous backup, will determine the time, larger than the last backup time of the file to synchronize again, or when the search file changes, when the hacker intrusion, will use this.
Atime: Access time, read file or execute file will change, command such as Cat,vi
Mtime: Modification time, the content of the file is changed, it will be changed, such as VI
CTime: Change the time, the label of the file, such as attributes, users, user groups, permissions, content, etc., will be changed, such as Chmod,chown,vi

#6. The timestamp of the file (timestamp) is one of the contents of the inode, which is understood from the Inode: CTime refers to the time when the inode was last changed, mtime refers to the time the file content was last modified, and atime refers to the time the file was last opened.

#7. Atime does not necessarily have to be modified after accessing the file, because: when using the Ext3 file system, if the Noatime parameter is used in Mount, then the atime information is not updated, it is not want to filesystem do too much modification, and improve read performance.

Under the Linux system, use the stat (show inode information) command to view some information about a file, let's try it first.

Simply introduce the files that the Stat command displays. Additional Information:
-File: Show file name
-Size: Show file size
-Blocks: Total number of data blocks used by the file
-IO Block:io block size
-Regular file: Document type (regular file)
-Device: Unit number
-Inode:inode No.
-Links: Link count
-Access: Permissions for files
-GID, UID: the GID and UID of the file ownership.

Three times under Linux:
1. Access time: abbreviated to Atime, which indicates when the file was accessed. Update this time when the contents of the file are accessed
2. Modify Time: Abbreviated to Mtime, which indicates when the content of the file was modified, and when the data content of the file was modified, the time is updated.
3. Change time: Abbreviated to CTime, indicating the status of the file, when the status of the file is modified, update this time, such as the number of links to the file, size, permissions, blocks number.

The first three of the time is exactly the same, because I created it while modifying its content, so it's size, blocks also changed, also equivalent to a visit, so I quit the save three time after the same.

One by one verification is performed below.

Update for 1.atime (Access time)

Update for 2.mtime (modified time)

Here I used the echo command to write a line to the Hello.cpp file, and was surprised to find that more than Mtime was updated, and CTime was updated. What is this about? The reason is very simple, said earlier, CTime in the file size, blocks changes will also be updated, so carefully observe, whether these two information has changed?
Update for 3.ctime (status time)


The status time is updated again after you modify the Hello.cpp file permissions with the chmod directive.
If you do not take these actions to cause the system to update themselves these three times, there is no way to artificially change these three time? The answer is yes, please keep looking down ~

Touch command
We all know that the touch command is used to create a file, in fact, it uses another, is to modify the file timestamp.
Usage:
-A or –time=atime or –time=access or –time=use only change the access time.
-M or –time=mtime or –time=modify only change the modified time
-D,-T to specify the period of time,?? The time now
Let's give it a try:

By discovering, I just tried to modify the access time of the hello.cpp with the-a option, and the result CTime (state time) changed. Even though I actually changed the atime with touch, the status of the files changed, so CTime updated itself.

Yes, as above, I just changed the file modification time with the-M option, and CTime is still updated. The touch command still modifies the modification time only, and the state time is updated by the system itself.

Linux System stat instruction usage

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.