stat命令可以获取文件的详细信息
[root@localhost ~]# stat anaconda-ks.cfg
File: ‘anaconda-ks.cfg’
Size: 1662 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 68279761 Links: 1
Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-06-10 02:45:24.959342867 +0800
Modify: 2019-06-10 02:43:18.884898228 +0800
Change: 2019-06-10 02:43:18.884898228 +0800
Birth: -
从这里可以看到三个时间
Access : 文件最近一次被访问的时间
Modify: 文件内容最近一次被修改的时间
Change: 文件属性最近一次被改变的时间(属主、属组、权限、大小等)
[root@localhost test]# stat a.txt
File: ‘a.txt’
Size: 2 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 203720750 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-07-01 21:12:20.149589732 +0800
Modify: 2019-07-01 21:12:20.149589732 +0800
Change: 2019-07-01 21:12:20.149589732 +0800
Birth: -
[root@localhost test]# cat a.txt
a
[root@localhost test]# stat a.txt
File: ‘a.txt’
Size: 2 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 203720750 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-07-01 21:14:21.096339337 +0800
Modify: 2019-07-01 21:12:20.149589732 +0800
Change: 2019-07-01 21:12:20.149589732 +0800
Birth: -
[root@localhost test]# stat a.txt
File: ‘a.txt’
Size: 2 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 203720750 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-07-01 21:14:21.096339337 +0800
Modify: 2019-07-01 21:12:20.149589732 +0800
Change: 2019-07-01 21:12:20.149589732 +0800
Birth: -
[root@localhost test]# echo 2 >> a.txt
[root@localhost test]# stat a.txt
File: ‘a.txt’
Size: 4 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 203720750 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-07-01 21:14:21.096339337 +0800
Modify: 2019-07-01 21:15:29.012607988 +0800
Change: 2019-07-01 21:15:29.012607988 +0800
Birth: -
[root@localhost test]# stat a.txt
File: ‘a.txt’
Size: 4 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 203720750 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-07-01 21:14:21.096339337 +0800
Modify: 2019-07-01 21:15:29.012607988 +0800
Change: 2019-07-01 21:15:29.012607988 +0800
Birth: -
[root@localhost test]# mv a.txt b.txt
[root@localhost test]# stat b.txt
File: ‘b.txt’
Size: 4 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 203720750 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-07-01 21:14:21.096339337 +0800
Modify: 2019-07-01 21:15:29.012607988 +0800
Change: 2019-07-01 21:16:40.556443329 +0800
Birth: -
只是看看,不做修改,并且通过q退出,只有access变化
[root@localhost test]# stat b.txt
File: ‘b.txt’
Size: 4 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 203720750 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-07-01 21:14:21.096339337 +0800
Modify: 2019-07-01 21:15:29.012607988 +0800
Change: 2019-07-01 21:16:40.556443329 +0800
Birth: -
[root@localhost test]# vim b.txt
[root@localhost test]# stat b.txt
File: ‘b.txt’
Size: 4 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 203720750 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-07-01 21:18:20.695226659 +0800
Modify: 2019-07-01 21:15:29.012607988 +0800
Change: 2019-07-01 21:16:40.556443329 +0800
Birth: -
如果wq保存退出,不管有没有修改文件内容,三个时间都变
[root@localhost test]# stat b.txt
File: ‘b.txt’
Size: 4 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 203720750 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-07-01 21:18:20.695226659 +0800
Modify: 2019-07-01 21:15:29.012607988 +0800
Change: 2019-07-01 21:16:40.556443329 +0800
Birth: -
[root@localhost test]# vim b.txt
[root@localhost test]# stat b.txt
File: ‘b.txt’
Size: 4 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 203720752 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-07-01 21:18:52.200187770 +0800
Modify: 2019-07-01 21:18:52.200187770 +0800
Change: 2019-07-01 21:18:52.201187831 +0800
Birth: -
touch -a 操作示范
[root@localhost test]# touch -a b.txt
[root@localhost test]# stat b.txt
File: ‘b.txt’
Size: 4 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 203720752 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-07-01 21:21:53.060012162 +0800
Modify: 2019-07-01 21:18:52.200187770 +0800
Change: 2019-07-01 21:21:53.060012162 +0800
Birth: -
touch -m 操作示范
[root@localhost test]# touch -m b.txt
[root@localhost test]# stat b.txt
File: ‘b.txt’
Size: 4 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 203720752 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-07-01 21:21:53.060012162 +0800
Modify: 2019-07-01 21:23:51.953952473 +0800
Change: 2019-07-01 21:23:51.953952473 +0800
Birth: -
touch 操作示范
[root@localhost test]# touch b.txt
[root@localhost test]# stat b.txt
File: ‘b.txt’
Size: 4 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 203720752 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-07-01 21:24:19.196538615 +0800
Modify: 2019-07-01 21:24:19.196538615 +0800
Change: 2019-07-01 21:24:19.196538615 +0800
Birth: -