Linux下文件的三个时间意义及用法

Linux下文件的三个时间参数:

    (1)modification time(mtime):内容修改时间
        这里的修改时间指的是文件的内容发生变化,而更新的时间。

    (2)change time(ctime):状态修改时间
        这里的修改时间指的是文件的属性或者权限发生变化,而更新的时间。

    (3)access time(atime):最后访问时间
        这里的访问时间是指文件被读取,而更新的时间。

在Linux下操作命令分别为:

ls -l    获取文件最后一次内容修改的时间(modification time(mtime))

ls -lu   获取文件最后一次访问的时间(change time(ctime))

ls -lc   获取文件最后一次状态的改变时间(access time(atime))


在Linux下文件没有创建时间这个概念,若文件从创建后不曾修改过则可认为 创建时间=修改时间

下面通过事例验证:

事例1:

# 直接touch一个test文件并查看时间

[root@localhost ~]# touch test; stat test
  File: ‘test’
  Size: 0             Blocks: 0          IO Block: 4096   regular empty file
Device: fd00h/64768d    Inode: 269422829   Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2017-05-31 11:02:38.050000000 +0800
Modify: 2017-05-31 11:02:38.050000000 +0800
Change: 2017-05-31 11:02:38.050000000 +0800
 Birth: -

总结:
    当新创建一个文件时,这个文件的最后访问时间、最后内容修改时间、最后状态更新时间都是一致的。

事例2:

# 修改该文件的权限属性状态:

[root@localhost ~]# chmod 777 test ; stat test
  File: ‘test’
  Size: 0             Blocks: 0          IO Block: 4096   regular empty file
Device: fd00h/64768d    Inode: 269422829   Links: 1
Access: (0777/-rwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2017-05-31 11:02:38.050000000 +0800
Modify: 2017-05-31 11:02:38.050000000 +0800
Change: 2017-05-31 11:05:27.816000000 +0800
 Birth: -

总结:
    修改一个文件的权限状态信息,只会更新这个文件的最后状态修改时间。

事例3:

# 修改该文件的内容信息:

[root@localhost ~]# echo hello > test ; stat test 
  File: ‘test’
  Size: 6             Blocks: 8          IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 269422829   Links: 1
Access: (0777/-rwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2017-05-31 11:02:38.050000000 +0800
Modify: 2017-05-31 11:06:59.638000000 +0800
Change: 2017-05-31 11:06:59.638000000 +0800
 Birth: -

总结:
    对比事例2,这里最后状态时间、最后内容改变时间都被更新了。 当修改一个文件时,文件的Modify、Change会被更新。


事例4:

# 查看该文件

[root@localhost ~]# cat test ; stat test 
hello

  File: ‘test’
  Size: 5             Blocks: 8          IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 269422829   Links: 1
Access: (0777/-rwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2017-05-31 11:10:03.470000000 +0800
Modify: 2017-05-31 11:08:29.717000000 +0800
Change: 2017-05-31 11:08:29.717000000 +0800
 Birth: -

总结:
    当查看文件时,文件的 Access time 会更新。

linux文件状态的三个时间总结如下:

当需要了解这个文件有没有被修改过 -  Modify Time
当需要了解这个文件最后被查看的时间 - Access Time
当需要了解这个文件权限最后变动的时间 - Change Time

扩展:

查找1天前未更新内容的文件并删除

find . -type f -mtime +1 | xargs rm -rf 
原文地址:https://www.cnblogs.com/hukey/p/6923289.html