linux三类时间详解

  Linux文件与目录的三种时间状态
1. mtime(modify time): 最后一次修改文件或目录的时间
2. ctime(change time) : 最后一次改变文件或目录( 改变的是原数据即: 属性) 的时间
:记录该文件的inode节点被修改的时间。touch命令除了-d-t选项外都会改变该时间。而且chmod,chown等命令也能改变该值。
3. atime(access time):: 最后一次访问文件或目录的时间
    对于文件:
当修改mtime ,ctime 必须随着改变. 因为文件大小等都是属性;
有人说说atime也一定会改变,要想修改文件必须先访问;其实是不对的 不必访问文件就能修改其内容:
如: #echo “This is a test !” >> /etc/issue,
issue 文件内容会变,但并没有访问文件,所以atime 并没有改变.

对于目录:
      访问一个目录其atime 改变,mtime  ctime 不变;
     修改一个目录: 在一个目录下touch 一个文件, mtimectime会改变,atime不一定会变;
[root@station16 ~]# stat /tmp
  file: `/tmp'
  size: 135168          Blocks: 280        IO Block: 4096   directory
fevice: fd00h/64768d    Inode: 2555905     Links: 8
access: (1777/drwxrwxrwt)  Uid: (    0/    root)   Gid: (    0/    root)
access: 2010-07-09 09:15:59.000000000 +0800
modify: 2010-07-09 09:15:57.000000000 +0800
change: 2010-07-09 09:15:57.000000000 +0800

[root@station16 ~]# cd /tmp
[root@station16 tmp]# touch text.txt
[root@station16 tmp]# cd
[root@station16 ~]# !s
stat /tmp
  file: `/tmp'
  size: 135168          Blocks: 280        IO Block: 4096   directory
device: fd00h/64768d    Inode: 2555905     Links: 8
access: (1777/drwxrwxrwt)  Uid: (    0/    root)   Gid: (    0/    root)
access: 2010-07-09 09:15:59.000000000 +0800
modify: 2010-07-09 09:31:39.000000000 +0800
change: 2010-07-09 09:31:39.000000000 +0800
[root@station16 ~]#
 
atime改变,mtime ctime不变情况
 
[root@station16 ~]# stat /tmp
  File: `/tmp'
  Size: 135168          Blocks: 280        IO Block: 4096   directory
device: fd00h/64768d    Inode: 2555905     Links: 8
access: (1777/drwxrwxrwt)  Uid: (    0/    root)   Gid: (    0/    root)
access: 2010-07-09 09:15:59.000000000 +0800
modify: 2010-07-09 09:31:39.000000000 +0800
change: 2010-07-09 09:31:39.000000000 +0800
[root@station16 ~]# cd /tmp
[root@station16 tmp]# ls
aa  text  text.txt
[root@station16 tmp]# cd
[root@station16 ~]# !s
stat /tmp
  file: `/tmp'
  size: 135168          Blocks: 280        IO Block: 4096   directory
device: fd00h/64768d    Inode: 2555905     Links: 8
access: (1777/drwxrwxrwt)  Uid: (    0/    root)   Gid: (    0/    root)
access: 2010-07-09 09:35:49.000000000 +0800
modify: 2010-07-09 09:31:39.000000000 +0800
change: 2010-07-09 09:31:39.000000000 +0800
[root@station16 ~]#
 
 
使用stat命令可以查看三时间值: stat filename
 
 
也可使用:
         ls -l file :  查看文件修改时间
        
ls -lc file:  查看文件状态改动时间
        
ls -lu file:  查看文件访问时间
 
touch命令更改文件时间属性的介绍 

touch 命令   选项   [options] 的时间格式 [[CC]YY]MMDDhhmm[.ss] 说明 :
CC 表示世纪
YY 表示年
MM
表示月
DD
表示日
hh
表示小时
mm
表示分钟
ss
表示秒
201001311200.34
CCYYMMDDhhmm ss
表示时间为 2010 1 31 12 0 34
options :
      -t:    后面可接时间,其格式如上所述
      -a :仅修改 access time
      -c :仅修改ctime时间,而不建立文件
      -m :仅修改 mtime
例如:将 issue 文件日期改为 2008/07/15  13:13
 [root@station16 ~]# ls -l /etc/issue
-rw-r--r-- 1 root root 80 Jul  8 09:03 /etc/issue
[root@station16 ~]# touch -t 0807151313    /etc/issue
[root@station16 ~]# !l
ls -l /etc/issue
-rw-r--r-- 1 root root 80 Jul 15  2008 /etc/issue
[root@station16 ~]# stat /etc/issue
  File: `/etc/issue'
  Size: 80              Blocks: 16         IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 3014852     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2008-07-15 13:13:00.000000000 +0800
Modify: 2008-07-15 13:13:00.000000000 +0800
Change: 2010-07-09 09:51:46.000000000 +0800
注意到,我们改变了issue mtime atime ,并没有改变ctime, 此时的ctime 记录的是当前时间。


posted @ 2017-02-16 23:04  乐天的java  阅读(136)  评论(0)    收藏  举报