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 creation time under 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 = set time, if the file is established, has not been 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 the determination of the file settling time is basically impossible. How to check a file for three time? use the following command to create a file
# date && echo "This is file being used test time of file" >filetime.txt && ll--full-time filetime.tx T
Tue 4 15:13:44 HKT
-rw-r--r--1 root root 2009-08-04 15:13:44.000000000 +0800 filetime.txt
Check by stat filename.txt, such as:
# stat Filetime.txt
File: ' Filetime.txt '
size:39 blocks:8 IO block:4096 Regular File
device:802h/2050d inode:17 links:1
Access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root)
access:2009-08-04 15:13:44.000000000 +0800
modify:2009-08-04 15:13:44.000000000 +0800
change:2009-08-04 15:13:44.000000000 +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, use more, cat and other commands for this file. 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:#/Sbin/mkfs-t EXT3/DEV/RAM10# mount-t Ext3-o noatime/dev/loop0/mnt/foo# Mount/DEV/RAM10 on/mnt/foo type ext3 (rw,noatime)# Cd/mnt/foo# Touch Filetime1.txt# stat Filetime1.txt
File: ' Filetime1.txt '
size:0 blocks:0 IO block:4096 Regular File
device:10ah/266d inode:12 links:1
Access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root)
access:2009-08-04 20:51:32.000000000 +0800
modify:2009-08-04 20:51:32.000000000 +0800
change:2009-08-04 20:51:32.000000000 +0800 # echo Foo.ok >> filetime1.txt
[email protected] foo]# stat filetime1.txt
File: ' Filetime1.txt '
size:14 blocks:2 IO block:4096 Regular File
device:10ah/266d inode:12 links:1
Access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root)
access:2009-08-04 20:51:32.000000000 +0800
modify:2009-08-04 20:53:27.000000000 +0800
change:2009-08-04 20:53:27.000000000 +0800 # cat Filetime1.txt
Foo.ok
#stat filetime1.txt
File: ' Filetime1.txt '
size:14 blocks:2 IO block:4096 Regular File
device:10ah/266d inode:12 links:1
Access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root)
access:2009-08-04 20:51:32.000000000 +0800
modify:2009-08-04 20:53:27.000000000 +0800
change:2009-08-04 20:53:27.000000000 +0800 # using the above experiment, you can see that the file's access time is constant. then test it down a little bit.# VI Filetime1.txt# stat Filetime1.txt
File: ' Filetime1.txt '
size:23 blocks:2 IO block:4096 Regular File
device:10ah/266d inode:14 links:1
Access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root)
access:2009-08-04 20:55:05.000000000 +0800
modify:2009-08-04 20:55:05.000000000 +0800
change:2009-08-04 20:55:05.000000000 +0800 # chmod 777 Filetime1.txt
# stat Filetime1.txt
File: ' Filetime1.txt '
size:23 blocks:2 IO block:4096 Regular File
device:10ah/266d inode:14 links:1
Access: (0777/-rwxrwxrwx) Uid: (0/root) Gid: (0/root)
access:2009-08-04 20:55:05.000000000 +0800
modify:2009-08-04 20:55:05.000000000 +0800
change:2009-08-04 20:57:36.000000000 +0800visible, chmod after the change of CTime. #########################################################speaking of which, we probably have some knowledge about the time of the file in Linux. So how does the following action affect the time of the file? Operation Atime Mtime CTime----------------------------------------------------------MV----------------------------------------------------------CP----------------------------------------------------------Touch----------------------------------------------------------cat/more/less----------------------------------------------------------ls----------------------------------------------------------Chmod/chown----------------------------------------------------------LN----------------------------------------------------------Echo----------------------------------------------------------VI----------------------------------------------------------(please test to complete this table!!!!) You can leave a message for me when I finish the test! )############################################################## also, from kernel2.6.29, a relatime attribute is integrated by default. It is possible that a system with very frequent file read operations, the atime update is expensive, so many SAS use the Noatime property to stop updating atime when mounting the file system. However, some programs need to be judged and manipulated according to Atime, so Linux has introduced a relatime feature.
using this feature to mount the file system, the Atime is updated only when Mtime is newer than atime. In fact, this time atime and Mtime are already the same thing. So this option was introduced to achieve compatibility with atime. is not a new time attribute. The way to use this is to mount the directory by Mount-o Relatime/dir.
"Reprint" Under Linux, a file also has three kinds of time, namely: Access time, modification time, state change time