Three time stamps of files in Linux

Source: Internet
Author: User
Tags filetime


In Linux, files are marked with three time periods: Creation Time, modification time, and access time. In Linux, a file has three types of time: Access time, modification time, and status modification time. There is a difference between www.2cto.com and www.2cto.com. There is no concept of Creation Time in Linux, so you cannot know the file creation time. However, if the file has not been modified after it is created, the modification time is equal to the creation time; if the state of the file has not been changed after the file is created, the state change time is set to the creation time. If the file has not been read after the file is created, the access time is set to the creation time, it is difficult to determine whether a file has been changed, read, or changed in the State. Therefore, it is impossible to determine the file creation time. How can I query the time of a file? Use the following command to create a file # date & echo "this is file be used test time of file"> filetime.txt & ll -- full-time filetime.txt Tue Aug 4 15:13:44 HKT 2009-rw-r -- r -- 1 root 39 15:13:44. 000000000 + 0800 filetime.txt is queried through stat filename.txt, for example: # stat filetime.txt File: 'filetime.txt 'Size: 39 Blocks: 8 IO Block: 4096 Regular FileDevice: 802 h/2050d Inode: 17 Links: 1 Access: (0644/-rw-r --) Uid: (0/ Root) Gid: (0/root) Access: 15:13:44. 000000000 + 0800 Modify: 15:13:44. 000000000 + 0800 Change: 15:13:44. 000000000 + 0800 Note: Access time. Modify modification time. Change status Change time. You can use stat * to view the status of all files in this directory. Ctime = change timeatime = access timemtime = modifiy time because this is a new file (filetime.txt), NO content or attribute changes have been made, and this file has not been read, so the three (access time, modification time, Status change time) the modification time of the file is the same as that of the three files. 1. Access time: Read the content of this file once, and the time will be updated. For example, use more or cat commands for this file. The ls and stat commands do not modify the file access time. 2. modification time. The modification time is the last modification time of the file content. For example, save the file after vi. The time listed by ls-l is this time. 3. Status change time. Is the last time the I node of the file was modified. You can use the chmod and chown commands to modify the file attributes. This time will be updated. In addition to viewing attributes such as mtime, ctime, and atime of the file through stat, you can also view the attributes by using the ls command, as shown below: 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 modification time) in the stat function in linux, st_atime is used to represent the last accessed time of the file data; st_mtime is used to represent the last modified time of the file data ); use st_ctime to indicate the last I-node's status changed time of the file I node data ). Field Description Example ls (-l) last access time of the st_atime file data read-u st_mtime file data last modification time write default st_ctime file data last modification time chown, in linux, the chmod-c system stores file content data and I node data separately, and I node data stores file permissions and file owner data. In addition, you can format the output file at three 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 indicates the file modification time, if the file has been modified, it is difficult to know the file creation time. In some special cases, you need to view the file creation time. Normally, viewing the file ctime is impossible. You can use a work und to retain the File Creation Time, but it also sacrifices some other features. You can use the-o noatime parameter when mounting a file to disable the atime feature of system updates. After the noatime parameter is used for mounting, The atime of the file will not be changed after the file is modified. The atime displayed by using stat is the file creation time. For example: #/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 FileDevice: 10ah/266d Inode: 12 Links: 1 Access: (0644/-rw-r --) Uid: (0/root) Gid: (0/root) Access: 20:51:32. 000000000 + 0800 Modify: 20 20:51:32 09-08-04. 000000000 + 0800 Change: 20:51:32. 000000000 + 0800 # echo foo. OK> filetime1.txt [root @ logs-bak foo] # stat filetime1.txt File: 'filetime1.txt 'Size: 14 Blocks: 2 IO Block: 4096 Regular FileDevice: 10ah/266d Inode: 12 Links: 1 Access: (0644/-rw-r --) Uid: (0/root) Gid: (0/root) Access: 20:51:32. 000000000 + 0800 Modify: 20:53:27. 000000000 + 0800 Chan Ge: 20:53:27. 000000000 + 0800 # cat filetime1.txt foo. OK # stat filetime1.txt File: 'filetime1.txt 'Size: 14 Blocks: 2 IO Block: 4096 Regular FileDevice: 10ah/266d Inode: 12 Links: 1 Access: (0644/-rw-r --) Uid: (0/root) Gid: (0/root) Access: 20:51:32. 000000000 + 0800 Modify: 20:53:27. 000000000 + 0800 Change: 20:53:27. 000000000 + 0800 # The above experiment shows the File access Time is unchanged. Next, let's test it more. # vi filetime1.txt # stat filetime1.txt File: 'filetime1.txt 'size: 23 Blocks: 2 IO Block: 4096 Regular FileDevice: 10ah/266d Inode: 14 Links: 1 Access: (0644/-rw-r --) Uid: (0/root) Gid: (0/root) Access: 20:55:05. 000000000 + 0800 Modify: 20:55:05. 000000000 + 0800 Change: 20:55:05. 000000000 + 0800 # chmod 777 filetime1.txt # stat filetime1.txt File: 'filet Ime1.txt 'size: 23 Blocks: 2 IO Block: 4096 Regular FileDevice: 10ah/266d Inode: 14 Links: 1 Access: (0777/-rwxrwxrwx) Uid: (0/root) gid: (0/root) Access: 20:55:05. 000000000 + 0800 Modify: 20:55:05. 000000000 + 0800 Change: 20:57:36. 000000000 + 0800: Ctime changes after chmod. ######################################## ###################### In addition, from kernel2.6.29, A relatime attribute is also integrated by default. This may be because atime update overhead is very high in systems with frequent File Read operations. Therefore, many SAS use the noatime attribute to stop updating atime when mounting the file system. However, some programs need to make some judgments and Operations Based on atime, so Linux has introduced a relatime feature. After this feature is used to mount the file system, atime will be updated only when mtime is better than atime. In fact, atime and mtime are already the same thing at this time. Therefore, this option is available only for compatibility with atime. It is not a new time attribute. You can use mount-o relatime/dir to mount the directory.

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.