The real meaning of the find command -atime, -ctime, -mtime under linux

The meaning of -atime, -ctime, -mtime under linux
We are often asked in forums or groups, how to check the creation date of a file under linux or unix?
It is often said that the option -ctime is added to the find command. In fact, the -ctime here is not create time, but change time.
In operating systems such as linux or unix, the creation date of the file is not saved for us.

[@more@]

The meaning of -atime, -ctime, -mtime under linux
We are often asked in forums or groups, how to check the creation date of a file under linux or unix?
It is often said that the option -ctime is added to the find command. In fact, the -ctime here is not create time, but change time.
In operating systems such as linux or unix, the creation date of the file is not saved for us.
We can first take a look at the status information of the files in the linux system. The following file was created by me a week ago:
[root@ora01 ~]# stat 3
File: “3”
Size: 15 Blocks: 8 IO Block: 4096 General file
Device: fd00h/64768d Inode: 489602 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2012-07-17 22:14 :55.000000000 +0800
Modify: 2012-07-17 15:22:45.000000000 +0800
Change: 2012-07-17 15:22:45.000000000 +0800
You can see that there are three times in the file status, namely access, modify, change .
Let's take a look at the options under the find command:
[oracle@ora01 admin]$ man find
-atime n
File was last accessed n*24 hours ago. When find figures out how many 24-hour periods ago the file was last accessed, any fractional
part is ignored, so to match -atime +1, a file has to have been accessed at least two days ago.
-mtime n
File’s data was last modified n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file
modification times. 
-ctime n
File’s status was last changed n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file
status change times.


It is found that the three times are exactly the same as the three time states of the file, and the help has clearly told us its specific meaning:
atime means access time, that is, the last access time of the file, +n means search n For files older than days, -n is to find files within n days.
For example, there is a file data4.txt, check its status:
[oracle@ora01 ~]$ stat data4.txt
File: `data4.txt'
Size: 49 Blocks : 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 458037 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 500/ oracle) Gid: ( 500/oinstall)
Access: 2012-07-10 11:46:05.000000000 +0800 Modify: 2012-07-10 11:44:37.000000000 +0800
Change: 2012-07-10 11:44:37.000000000 +0800
Let's check its contents:
[oracle @ora01 ~]$ more data4.txt 
"SCOTT",12,"F444"
"BRENTT",43,"54GSS"
"SYS",4566
Let's take a look at the status of the file:
[oracle@ora01 ~]$ stat data4.txt 
File: `data4.txt'
Size: 49 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 458037 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 500/ oracle) Gid: ( 500/oinstall)
Access: 2012-07-22 23:21:10.000000000 +0800 Modify: 2012-07-10 11:44:37.000000000 +0800
Change: 2012-07-10 11:44:37.000000000 + 0800
can be found, as long as you view the content of the file, whether it is more, cat, vi, then the access time of the file will be updated.

mtime is easy to understand. It is modify time, that is, the latest modification time of the file data, which refers to the latest modification time of the file content.
[oracle@ora01 ~]$ stat ctl1.txt
File: `ctl1.txt'
Size: 288 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 458031 Links: 1
Access: (0644/-rw-r --r--) Uid: ( 500/ oracle) Gid: ( 500/oinstall)
Access: 2012-07-22 23:46:05.000000000 +0800
Modify: 2012-07-10 11:44:05.000000000 +0800 Change: 2012-07-10 11:44:05.000000000 +0800
Edit the file:
[oracle@ora01 ~]$ echo "" >>ctl1.txt
[oracle@ora01 ~]$ stat ctl1.txt 
File: `ctl1.txt '
Size: 291 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 458070 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 500/ oracle) Gid: ( 500 /oinstall)
Access: 2012-07-22 23:46:05.000000000 +0800
Modify: 2012-07-22 23:46:31.000000000 +0800
Change: 2012-07-22 23:46:31.000000000 +0800
Found both the modify and change times of the file Changed, the change time is discussed below.

ctime means change time, the time when the state of the file was last changed. Is the status change time of the file, what is the status of the file?
We all know that files have some basic attributes, permissions, users, groups, sizes, modification times, etc. As long as these information changes, the ctime will change,
so why does the ctime change when the file content is modified above, because its mtime Has changed, mtime is also one of the file states.
The file status can be viewed through ls -l:
[root@ora01 ~]# ls -l 3
-rw-r--r-- 1 root root 15 07-17 15:22 3
The change time of the following file is 2012-07 -17:
[root@ora01 ~]# stat 3
File: “3”
Size: 15 Blocks: 8 IO Block: 4096 General File
Device: fd00h/64768d Inode: 489602 Links: 1
Access: (0644/-rw-r- -r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2012-07-17 22:14:55.000000000 +0800
Modify: 2012-07-17 15:22:45.000000000 +0800
Change: 2012 -07-17 15:22:45.000000000 +0800 Let's change its permissions:
[root@ora01 ~]# chmod 755 3
Let's take a look at its Change time:
[root@ora01 ~]# stat 3
File: “3”
Size: 15 Blocks: 8 IO Block: 4096 General file
Device: fd00h/64768d Inode: 489602 Links: 1
Access: (0755/ -rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2012-07-17 22:14:55.000000000 +0800
Modify: 2012-07-17 15:22:45.000000000 +0800
Change : 2012-07-22 23:17:40.000000000 +0800 Change its user again:
[root@ora01 ~]# chown oracle.root 3
[root@ora01 ~]# stat 3
File: “3”
Size: 15 Blocks : 8 IO Block: 4096 General File
Device: fd00h/64768d Inode: 489602 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 500/ oracle) Gid: ( 0/ root)
Access: 2012-07 -17 22:14:55.000000000 +0800
Modify: 2012-07-17 15:22:45.000000000 +0800
Change: 2012-07-22 23:33:59.000000000 +0800 Change the group it belongs to:
[root@ora01 ~]# chgrp oinstall 3
[root@ora01 ~]# ll
total 4
-rwxr-xr-x 1 oracle oinstall 15 07-17 15:22 3
[root@ora01 ~]# stat 3
File: “3”
Size: 15 Blocks: 8 IO Block: 4096 General File
Device: fd00h/64768d Inode: 489602 Links: 1
Access: (0755 /-rwxr-xr-x) Uid: ( 500/ oracle) Gid: ( 500/oinstall)
Access: 2012-07-17 22:14:55.000000000 +0800
Modify: 2012-07-17 15:22:45.000000000 +0800
Change: 2012-07-22 23:36:14.000000000 +0800 I found that as long as any information in ls -l is modified, the change time will change.

Summary: The ctime in the find command is not the creation time, but the file state change time. The three time attributes of the file are access time, modify time and change time.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324780198&siteId=291194637