Under Windows, a file has: creation time, modification time, access time.
And under Linux, a file also has three kinds of time, namely: Access time, modification time, state change time.
There is a difference between the two, there is no concept of creating time in Linux, that is, the creation time of the file is not known, but if the file is not modified after the establishment, the modification time = set time, if the file is established, the state has not changed, then the state change time = setup time, if the file is established, not read, Then the access time = settling time, because it is not good to judge whether the file has been changed, read, and its status is changed, so it is almost impossible to determine the file settling time.
How to check a file for three time?
Use the following command to create a file
" New File " > File.txt
[Email protected] wm]#Stat file. txt File: 'file. txt'Size:9Blocks:8IO Block:4096Regularfiledevice:801h/2049D Inode:5255731Links:1Access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root) Access: the- ,- A -: A:15.058576627+0800Modify: the- ,- A -: A:15.058576627+0800Change : the- ,- A -: A:15.058576627+0800
Description: Access time for access. Modify modification time. Change state changes time. Can stat * View the status of all files in this directory.
Ctime=change time
Atime=access time
Mtime=modifiy time
Because this is a new file (Filetime.txt), did not make the content, the property changes, also did not read this file, so the three (access time, modification time, state change time) time is consistent, when the file modification time and these three time is the same, there is no doubt.
1, Access time, read the contents of this file, this time will be updated. For example, the use of the file more, cat and other commands (note here, sometimes input VI will also modify the access time, because also need to access content). The LS, stat command does not modify the file access time.
2, Modified time, modified time is the last time the file content was modified. For example: VI after saving files. The time that ls-l lists is this time.
3, state change time. Is the last time the file's I node was modified, and the file properties are modified by the chmod, Chown command, and the time is updated.
The other in addition to the stat can be used to view the file Mtime,ctime,atime properties, but also through the LS command to view, as follows:
LS-LC filename List file CTime (last change time)
Ls-lu filename List file atime (last access time)
ls-l filename List file mtime (last modified)
In the stat function in Linux, St_atime is used to represent the most recent access time of the file data (last accessed times), and the st_mtime represents the last modification time of the file data, with St_ CTime represents the most recent modification time of the file I node data (last I-node ' s status changed times).
Field Description Example LS (-l)
St_atime last access time for file data read-u
St_mtime last modified time of file data write default
St_ctime The last change time of the file data chown,chmod-c
In Linux system, the system put the file content data and I node data are stored separately, I node data storage file permissions and file owner and other data.
In addition, you can format the output file for three different times, such as:
Find. -name file-printf "%ay-%am-%ad%ah:%am:%as"
Find. -name file-printf "%ty-%tm-%td%th:%tm:%ts"
Find. -name file-printf "%CY-%CM-%CD%ch:%cm:%cs"
Linux CTime represents the file modification time, if the file has been modified it is difficult to know the creation time of the file, in some special cases, you need to view the file creation time, under normal circumstances to view the file CTime is not possible. You can use a workaround to preserve file creation time, but at the same time sacrifice some other features.
You can use the parameter-o noatime in the mount file to turn off the feature of the system update atime. After the Noatime parameter is mounted, the file's atime will not be changed after the file has been modified, and the atime you see with stat is the creation time of the file.
Such as:
[Email protected] wm]#Stat file. txt File: 'file. txt'Size:9Blocks:8IO Block:4096Regularfiledevice:801h/2049D Inode:5255731Links:1Access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root) Access: the- ,- A -: A:15.058576627+0800Modify: the- ,- A -: A:15.058576627+0800Change : the- ,- A -: A:15.058576627+0800[email protected] wm]#Cat file. txt Newfile[email protected] wm]#Stat file. txt File: 'file. txt'Size:9Blocks:8IO Block:4096Regularfiledevice:801h/2049D Inode:5255731Links:1Access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root) Access: the- ,- A -: -:31.512576521+0800Modify: the- ,- A -: A:15.058576627+0800Change : the- ,- A -: A:15.058576627+0800[email protected] wm]#
Get filename, file size, build date
[Email protected] wm]#ls-ltr--full- Time|grep-v Total-rw-r--r--1Root root1394 the- ,- - -: -:31.548634852+0800epollserver.c-rw-r--r--1Root root4651 the- ,- - +: Wu:20.000000000+0800A.cc-rw-r--r--1Root root123 the- ,- - A:xx:12.734631459+0800Utils.h-rw-r--r--1Root root1699 the- ,- - A:xx:47.147630750+0800local.h-rw-r--r--1Root root24678 the- ,- - A: on:12.171631554+0800Server.CPP-rw-r--r--1Root root1399 the- ,- - A: on:27.522631532+0800Tester.CPP-rw-r--r--1Root root43637 the- ,- - A: -:43.033631333+0800Client.CPP-rw-r--r--1Root root9 the- ,- A -: A:15.058576627+0800 file. Txt[[email protected] wm]#ls-ltr--full- Time|grep-V Total |awk-F" " '{printf "%-40s%-10d%-10s%-20s\n", $9,$5,$6,$7}'epollserver.c1394 the- ,- - -: -:31.548634852A.cc 4651 the- ,- - +: Wu:20.000000000Utils.h123 the- ,- - A:xx:12.734631459local.h1699 the- ,- - A:xx:47.147630750server.CPP 24678 the- ,- - A: on:12.171631554Tester.CPP 1399 the- ,- - A: on:27.522631532client.CPP 43637 the- ,- - A: -:43.033631333 file. txt9 the- ,- A -: A:15.058576627[email protected] wm]#
Turn from:
http://blog.csdn.net/wmengbeyond/article/details/38759953
Three time tags for linux files: Access time, modification time, status change Time (reprint)