3.文件管理
本章同步视频:https://edu.51cto.com/sd/e4874
3.2.5 touch - change file timestamps
atime:Access time,在读取文件或执行文件时更改。
mtime:Modifiedtime,在写入文件时随文件内容的更改而更改。
ctime:Change time,在写入文件、更改所有者、权限或链接设置时随inode的内容更改而更改。mtime改变,ctime随之改变。
(1)只有读取或者执行文件后,atime改变,而mtime,ctime不改变。
(2)只想文件写入内容后,mtime改变,ctime改变,而atime不改变。
(3)只修改inode信息(除文件内容)后,ctime改变,而atime,mtime不改变。
[root@localhost tmp]# touch aaa
#mtime,修改内容时间/创建时间
-rw-r--r--. 1 root root 0 3月 12 21:13 aaa
[root@localhost tmp]# ls -l --time=atime aaa
#atime,读取内容时间
-rw-r--r--. 1 root root 0 3月 12 21:13 aaa
[root@localhost tmp]# ls -l --time=ctime aaa
#ctime,修改属性时间
-rw-r--r--. 1 root root 0 3月 12 21:13 aaa
[root@localhost tmp]# chmod 666 aaa
-rw-rw-rw-. 1 root root 5 3月 12 21:31 aaa
[root@localhost tmp]# ll --time=atime aaa
-rw-rw-rw-. 1 root root 5 3月 12 21:31 aaa
[root@localhost tmp]# ll --time=ctime aaa
-rw-rw-rw-. 1 root root 5 3月 12 21:33 aaa #ctime改变
-rw-rw-rw-. 1 root root 5 3月 12 21:31 aaa
[root@localhost tmp]# ll --time=ctime aaa
-rw-rw-rw-. 1 root root 5 3月 12 21:33 aaa
[root@localhost tmp]# ll --time=atime aaa
-rw-rw-rw-. 1 root root 5 3月 12 21:35 aaa #atime改变
-rw-rw-rw-. 1 root root 10 3月 12 21:36 aaa #mtime改变
[root@localhost tmp]# ll --time=ctime aaa
-rw-rw-rw-. 1 root root 10 3月 12 21:36 aaa #ctime改变
[root@localhost tmp]# ll --time=atime aaa
-rw-rw-rw-. 1 root root 10 3月 12 21:35 aaa
[root@localhost tmp]# touch aaa
-rw-r--r--. 1 root root 0 Mar 12 22:41 aaa
[root@localhost tmp]# ll --time=atime aaa
-rw-r--r--. 1 root root 0 Mar 12 22:41 aaa
[root@localhost tmp]# ll --time=ctime aaa
-rw-r--r--. 1 root root 0 Mar 12 22:41 aaa
[root@localhost tmp]# touch -a aaa
[root@localhost tmp]# stat aaa
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd00h/64768d Inode: 7595 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:user_tmp_t:s0
Access: 2020-03-12 22:55:16.151176379 +0800
Modify: 2020-03-12 22:47:19.151147596 +0800
Change: 2020-03-12 22:55:16.151176379 +0800
[root@localhost tmp]# touch -m aaa
[root@localhost tmp]# stat aaa
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd00h/64768d Inode: 7595 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:user_tmp_t:s0
Access: 2020-03-12 22:55:16.151176379 +0800
Modify: 2020-03-12 22:56:09.743179613 +0800
Change: 2020-03-12 22:56:09.743179613 +0800
[root@localhost tmp]# touch -c aaa #或者 touch aaa
[root@localhost tmp]# stat aaa
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd00h/64768d Inode: 7595 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:user_tmp_t:s0
Access: 2020-03-12 22:57:14.750183535 +0800
Modify: 2020-03-12 22:57:14.750183535 +0800
Change: 2020-03-12 22:57:14.750183535 +0800
3.不管是修改atime,还是修改mtime,ctime都会变。
[root@localhost tmp]# touch -m -d "2 days ago" aaa
[root@localhost tmp]# stat aaa
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd00h/64768d Inode: 7595 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:user_tmp_t:s0
Access: 2020-03-12 22:57:14.750183535 +0800
Modify: 2020-03-10 23:10:32.056361925 +0800
Change: 2020-03-12 23:10:32.056231646 +0800
[root@localhost tmp]# touch -a -t 202005051010.10 aaa
[root@localhost tmp]# stat aaa
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd00h/64768d Inode: 7595 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:user_tmp_t:s0
Access: 2020-05-05 10:10:10.000000000 +0800
Modify: 2020-03-10 23:10:32.056361925 +0800
Change: 2020-03-12 23:13:18.713241702 +0800
#注:1.atime被修改为2020-05-05 10:10:10。