Linux查看和修改文件时间

参考http://www.361way.com/chang-file-time/1632.html

一:查看时间

1:查看文件的具体时间信息

  File: `probn'
  Size: 2             Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d    Inode: 913948      Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-10-31 20:00:00.000000000 +0800
Modify: 2016-10-31 20:00:00.000000000 +0800
Change: 2016-10-31 15:22:32.020285558 +0800

Access:访问时间    cat more less

Modify:修改内容时间    vim

Change:修改文件属性的时间   chmod  

2:用ls的方法查看

Access time   访问时间     :atime

ls -l --time=atime kkk

Modification time 修改时间:mtime  ls -l查看的时候默认的就是修改时间

ls -l

status time   状态时间      :ctime

ls -l --time=ctime kkk

二:修改文件的时间

touch 命令:

touch 一个已经存在的文件,只会修改时间

-a 修改文件的访问时间

[root@yunovo allapk]# touch -a -d "2009-11-11" kkk
[root@yunovo allapk]# stat kkk
  File: `kkk'
  Size: 0             Blocks: 0          IO Block: 4096   regular empty file
Device: 803h/2051d    Inode: 913948      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2009-11-11 00:00:00.000000000 +0800
Modify: 2016-10-31 09:00:00.000000000 +0800
Change: 2016-10-31 15:55:30.295285265 +0800

-m 修改文件的修改时间

[root@yunovo allapk]# touch -m -d "2010-10-18" kkk 
[root@yunovo allapk]# stat kkk
  File: `kkk'
  Size: 0             Blocks: 0          IO Block: 4096   regular empty file
Device: 803h/2051d    Inode: 913948      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2009-11-11 00:00:00.000000000 +0800
Modify: 2010-10-18 00:00:00.000000000 +0800
Change: 2016-10-31 15:56:11.510285082 +0800

-d 同时修改访问时间和修改时间

[root@yunovo allapk]# touch -d "2008-10-10" kkk 
[root@yunovo allapk]# stat kkk
  File: `kkk'
  Size: 0             Blocks: 0          IO Block: 4096   regular empty file
Device: 803h/2051d    Inode: 913948      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2008-10-10 00:00:00.000000000 +0800
Modify: 2008-10-10 00:00:00.000000000 +0800
Change: 2016-10-31 15:54:00.235285047 +0800

3:把后面文件夹的时间修改成和前一个文件一样,change这个时间还是自己的

touch -acmr kkk lll
原文地址:https://www.cnblogs.com/lemon-le/p/6016184.html