Three time tags for files under Linux: Access time, modification time, state change Time __linux

Source: Internet
Author: User
Tags chmod file permissions
Under Windows, a file has: creation time, modification time, access time.
In Linux, a file also has three kinds of time, namely: Access time, modification time, state change time.

There's a difference between the two, and there's no concept of creating time under Linux, that is, can not know the establishment of the file time, but if the file is not modified after the establishment, modify time = build time, if the file is established, the state has not changed, then the state change time = build time; If the file is established, it is not read, Then access time = establish time, because it is not good to judge whether the file has been changed, read, its status has changed, so the establishment of the time to determine the file can be basically impossible.

How to check a file for three time.

First use the following command to create a file

echo "New file" > file.txt

[root@cdntest69 wm]# stat file.txt
file: ' file.txt ' size:9 <span style= '
white-space:pre ' >	</span>blocks:8 IO block:4096 Regular file
device:801h/2049d<span style= "White-space:pre" >
  </span>inode:5255731 links:1
Access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root) 
  access:2014-08-22 17:41:15.058576627 +0800
modify:2014-08-22 17:41:15.058576627 +0800
change:2014-08-22 17:41:15.058576627 +0800

Description: Access access time. Modify modification time. Change state changes time. You 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), has not done the content, the attribute change, also did not read this file, therefore three (accesses the time, the modification time, the state changes time) the time is consistent, then the file modification time and these three time is same, is no question.

1, Access time, read the contents of this file, this time will be updated. such as the use of this document more, cat and other commands. The LS, stat command does not modify the access time of the file.
2, modified time, the modification time is the last time the contents of the file was modified. For example: Save the file after VI. The time that ls-l lists is this time.
3, state change time. Is the time when the I node of the file was last modified, and the file attributes are modified once by the chmod, Chown command, and this time is updated.

Another, in addition to the stat to view the file Mtime,ctime,atime properties, can also be viewed through the LS command, as follows:
LS-LC filename Lists the CTime of the file (last change time)
Ls-lu filename Lists the atime (last access time) of the file
ls-l filename Lists the mtime of the file (last modified)

In Linux, the stat function uses St_atime to represent the most recent access time for file data (last accessed), and St_mtime represents the most recent modification time for file data (last modified times); Use St_ CTime represents the most recent modification of the file I node data (last I-node's status changed time).

Field Description Example LS (-l)
St_atime the last access time for file data read-u
St_mtime file data Last modified time write default
St_ctime the last time the file data was changed chown,chmod-c

In Linux system, the file content data and the I node data are stored separately, and the I node data holds the data of file permissions and file owners.

In addition, you can format the output file in 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 file creation time, in some special circumstances, you need to see the creation time of the file, the normal view of the file CTime is not possible. You can use a workaround to keep the file creation time, but at the same time sacrificing some of the other features.

You can use parameter-o noatime in the mount file to turn off the system Update atime feature. Using the Noatime parameter mount, after the file is modified, the file atime will not be changed, using stat to see Atime is the file creation time.
Such as:

[root@cdntest69 wm]# stat file.txt 
  file: ' file.txt '
  size:9         	blocks:8          IO   block:4096 Regular c5/>device:801h/2049d	inode:5255731     links:1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
access:2014-08-22 17:41:15.058576627 +0800
modify:2014-08-22 17:41:15.058576627 +0800
change:2014-08-22 17:41:15.058576627 +0800
[root@cdntest69 wm]# cat File.txt 
New File
[root@cdntest69 wm]# stat file.txt 
  file: ' file.txt '
  size:9         	blocks:8          IO   block:4096 Regular File
device:801h/2049d	inode:5255731     links:1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
access:2014-08-22 17:44:31.512576521 +0800
modify:2014-08-22 17:41:15.058576627 +0800
change:2014-08-22 17:41:15.058576627 +0800

Get file name, file size, build date

[root@cdntest69 wm]# ls-ltr--full-time | Grep-v total-rw-r--r--1 root 1394 2014-08-18 20:38:31.548634852 +0800 epollserver.c-rw-r--r--1 root root 4651 2014-08-18 21:54:20.000000000 +0800 root root 123 2014-08-18 22:00:12.734631459 +0800 utils.h-rw-r--r --1 root 1699 2014-08-18 22:00:47.147630750 +0800 local.h-rw-r--r--1 root root 24678 2014-08-18 22:01:12.17163155 4 +0800 server.cpp-rw-r--r--1 root root 1399 2014-08-18 22:01:27.522631532 +0800 tester.cpp-rw-r--r--1 root root 4363 
7 2014-08-18 22:07:43.033631333 +0800 client.cpp-rw-r--r--1 root root 9 2014-08-22 17:41:15.058576627 +0800 file.txt [root@cdntest69 wm]# ls-ltr--full-time | Grep-v Total | Awk-f "" ' {printf "%-40s%-10d%-10s%-20s\n", $9,$5,$6,$7} ' epollserver.c 1394 2014-08-                                  20:38:31.548634852 4651 2014-08-18 21:54:20.000000000 utils.h 123 2014-08-18 22:00:12.734631459 local.h 1699 2014-08-18 22:00:47.147630750       24678 2014-08-18 22:01:12.171631554 Tester.cpp 1399 2014-08-18 22:01:27.522631532 client.cpp 43637 2014-08-18 22:07:43.033631333  E.txt 9 2014-08-22 17:41:15.058576627 [root@cdntest69 wm]#

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: 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.