linux文件时间属性 查看和修改文件时间
来源:互联网 发布:专业淘宝图片拍摄德州 编辑:程序博客网 时间:2024/05/18 00:16
Linux下一个文件有三个主要的变动时间,mtime,ctime,atime:
mtime(modification time):当文件的内容更改时,就会更新这个时间。
ctime(status time):当文件的状态被更改时,会更改这个时间,比如像文件的权限或者属性被更改时就会更改这个时间。
atime(access time):就是文件访问时间,当文件的内容被读取时就会更改这个时间。比如使用cat指令读取某个文件时,这个时间就会被更改。
者三个时间可以使用可以同过加 –time 参数来获取
ll 文件名 这种方式会默认展现mtime
ll –time=atime 文件名 获取atime
ll –time=ctime 文件名 获取ctime
[root@localhost tmp]# ll timetest -rw-r--r-- 1 root root 0 Oct 29 22:19 timetest[root@localhost tmp]# ll --time=atime timetest -rw-r--r-- 1 root root 0 Oct 29 22:19 timetest[root@localhost tmp]# ll --time=ctime timetest -rw-r--r-- 1 root root 0 Oct 29 22:19 timetest
上面这个例子中,我的文件是刚刚创建的,所以显示的时间都是一样的。可以过几分钟用cat指令访问这个文件,再使用chmod指令修改这个文件权限,在来查看这个文件的三个时间时,会发现有变化了。
有时候由于时区等问题,你的文件时间可能和标准时间不一致,这个时候就可以使用touch指令来修改文件时间。
把时间修改到三天前
[root@localhost tmp]# touch -d "3 days ago" timetest [root@localhost tmp]# ll timetest ; ll --time=atime timetest ; ll --time=ctime timetest -rw-r--r-- 1 root root 0 Oct 26 22:29 timetest-rw-r--r-- 1 root root 0 Oct 26 22:29 timetest-rw-r--r-- 1 root root 0 Oct 29 22:29 timetest
把时间修改到某一个具体的时间点
[root@localhost tmp]# touch -t 1710262210 timetest [root@localhost tmp]# ll timetest ; ll --time=atime timetest ; ll --time=ctime timetest -rw-r--r-- 1 root root 0 Oct 26 22:10 timetest-rw-r--r-- 1 root root 0 Oct 26 22:10 timetest-rw-r--r-- 1 root root 0 Oct 29 22:30 timetest
注意:上面两个指令都指修改了mtime和atime ,ctime并没有被修改,要想修改ctime可以使用touch -c 文件 来实现
[root@localhost tmp]# touch -c timetest [root@localhost tmp]# ll timetest ; ll --time=atime timetest ; ll --time=ctime timetest -rw-r--r-- 1 root root 0 Oct 29 22:35 timetest-rw-r--r-- 1 root root 0 Oct 29 22:35 timetest-rw-r--r-- 1 root root 0 Oct 29 22:35 timetest
touch -c 文件名 这个指令会修改文件的三个时间,当文件不存在时会创建文件
touch -a 文件名 这个指令我使用man来查看时,上面说明只会修改文件的访问时间,但是在实际操作的时候发现除了mtime每变之外,atime和ctime都发生了改变。这个就有点百思不得其解了。先在这做个标记吧,有大神知道也可以指点一下。
[root@localhost tmp]# touch -a timetest [root@localhost tmp]# ll timetest ; ll --time=atime timetest ; ll --time=ctime timetest -rw-r--r-- 1 root root 0 Oct 29 22:35 timetest-rw-r--r-- 1 root root 0 Oct 29 22:37 timetest-rw-r--r-- 1 root root 0 Oct 29 22:37 timetest
- linux文件时间属性 查看和修改文件时间
- linux下查看和修改文件时间
- linux 和freebsd查看文件修改、进入时间
- linux文件时间的查看和修改touch
- Linux 下查看文件修改时间 等
- linux 下查看文件 最后修改时间
- linux 下查看文件修改时间 等
- linux查看文件最近修改时间
- linux 下查看文件修改时间 等
- linux 文件时间查看及修改
- Linux 下修改文件的时间属性
- Linux下修改文件的时间属性
- Linux下修改文件的时间属性
- Linux下修改文件的时间属性
- Linux 下修改文件的访问时间和修改时间属性
- Linux文件时间属性
- linux修改文件时间
- Linux修改文件时间
- 【c++】实现顺序表
- 函数指针及从文件读取的列子
- FileSystemXmlApplicationContext、ClassPathXmlApplicationContext和XmlWebApplicationContext
- 云端管理与资源质量评定
- 泛型的学习及使用
- linux文件时间属性 查看和修改文件时间
- MarkDown常用语法
- python笔记4
- 计算机的发展阶段
- Android开发基础知识回顾
- 我为什么选择产品经理
- NOIP2015 运输计划
- 个人总结19
- 不同路径-LintCode