linux 文件时间查看及修改
来源:互联网 发布:dior homme男装知乎 编辑:程序博客网 时间:2024/06/05 18:08
- 1 查看文件时间 使用stat
- 2 查看文件时间 使用ls
- 3 文件时间修改 基本
- 4 文件时间修改 具体
- 5 总结三者关系
1, 查看文件时间, 使用stat
[root@web10 ~]# stat install.log File: “install.log” Size: 33386 Blocks: 80 IO Block: 4096 一般文件Device: fd00h/64768d Inode: 7692962 Links: 1Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)Access: 2012-07-13 16:02:34.000000000 +0800Modify: 2011-11-29 16:03:06.000000000 +0800Change: 2011-11-29 16:03:08.000000000 +0800
说明:Access访问时间。Modify修改时间。Change状态改变时间。可以stat *查看这个目录所有文件的状态。
而我们想要查看某文件的三个时间中的具体某个时间,并以年月日时分秒的格式保存。我们可以使用下面的命令:
[root@web10 ~]# stat install.log|grep -i Modify | awk -F. '{print $1}' | awk '{print $2$3}'| awk -F- '{print $1$2$3}' | awk -F: '{print $1$2$3}'20111129160306
2, 查看文件时间, 使用ls
相应的通过ls 查看时也有三个时间:
* 指的是文件的内容,而不是文件的属性。
* status time(ctime,状态时间):当该文件的”状态(status)”改变时,就会更新这个时间,举例来说,更改了权限与属性,就会更新这个时间。
* access time(atime,存取时间):当“取用文件内容”时,就会更新这个读取时间。举例来说,使用cat去读取 ~/.bashrc,就会更新atime了。
* 注意: modify-文件的属性被修改; change-文件的属性(权限,拥护者,时间..)被修改
[root@web10 ~]# ls -l --time=ctime install.log-rw-r--r-- 1 root root 33386 2011-11-29 install.log[root@web10 ~]# ls -l --time=atime install.log-rw-r--r-- 1 root root 33386 07-13 16:02 install.log
注意:ls参数里没有–mtime这个参数,因为我们默认通过ls -l查看到的时间就是mtime 。
3, 文件时间修改, 基本
- linux
touch -acmd “2017-11-20 09:20:23” abc.java
touch -acmt “20171120092023” abc.java - Aix
aix下,没有-d参数
touch -acmt “20171120092023” abc.java
4, 文件时间修改, 具体
创建文件我们可以通过touch来创建。同样,我们也可以使用touch来修改文件时间。touch的相关参数如下:
-a : 仅修改access time。
-c : 仅修改时间,而不建立文件。
-d : 后面可以接日期,也可以使用 –date=”日期或时间”
-m : 仅修改mtime。
-t : 后面可以接时间,格式为 [YYMMDDhhmm]
注:如果touch后面接一个已经存在的文件,则该文件的3个时间(atime/ctime/mtime)都会更新为当前时间。若该文件不存在,则会主动建立一个新的空文件。
[root@web10 ~]# touch install.log[root@web10 ~]# stat install.log File: “install.log” Size: 33386 Blocks: 80 IO Block: 4096 一般文件Device: fd00h/64768d Inode: 7692962 Links: 1Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)Access: 2012-07-13 16:21:50.000000000 +0800Modify: 2012-07-13 16:21:50.000000000 +0800Change: 2012-07-13 16:21:50.000000000 +0800
同样,使用ls ,查看到的结果也一样。
[root@web10 ~]# ls -l --time=ctime install.log-rw-r--r-- 1 root root 33386 07-13 16:21 install.log[root@web10 ~]# ls -l --time=atime install.log-rw-r--r-- 1 root root 33386 07-13 16:21 install.log[root@web10 ~]# ls -l install.log-rw-r--r-- 1 root root 33386 07-13 16:21 install.log
下面再看一个和touch不相关的例子:
[root@web10 ~]# cp /etc/profile .;ll --time=atime profile ;ll --time=ctime profilecp:是否覆盖“./profile”? y-rw-r--r-- 1 root root 1344 07-13 16:24 profile-rw-r--r-- 1 root root 1344 07-13 16:25 profile
因为我之前运行过这个命令一次,所以会出现覆盖,不过这个覆盖出的好,刚才让我们看到了atime和ctime的时间的差别。
我们再回到touch利用touch修改文件时间:
1. 同时修改文件的修改时间和访问时间touch -d "2010-05-31 08:10:30" install.log2. 只修改文件的修改时间touch -m -d "2010-05-31 08:10:30" install.log3. 只修改文件的访问时间touch -a -d "2010-05-31 08:10:30" install.log
下面再给一个rootkit木马常用的伎俩。就是把后一个文件的时间修改成和前一个相同。
touch -acmr /bin/ls /etc/sh.conf
另外touch还支持像date命令一样参数修改文件时间:
[root@web10 ~]# touch -d "2 days ago" install.log ; ll install.log-rw-r--r-- 1 root root 33386 07-11 16:35 install.log
5, 总结三者关系
三者关系文:件的访问时间,修改时间,及状态变化时间:
访问时间,读一次这个文件的内容,这个时间就会更新。比如对这个文件使用more命令。ls、stat命令都不会修改文件的访问时间。
修改时间,对文件内容修改一次,这个时间就会更新。比如:vim后保存文件。ls -l列出的时间就是这个时间。
状态改变时间。通过chmod命令更改一次文件属性,这个时间就会更新。查看文件的详细的状态、准确的修改时间等,可以通过stat命令 文件名。
- linux 文件时间查看及修改
- Linux 下查看文件修改时间 等
- linux 下查看文件 最后修改时间
- linux 下查看文件修改时间 等
- linux下查看和修改文件时间
- linux查看文件最近修改时间
- linux 下查看文件修改时间 等
- linux学习笔记之查看文件状态及修改文件时间
- linux文件时间属性 查看和修改文件时间
- Linux下如何查看文件秒级修改及访问时间
- Linux下如何查看文件秒级修改及访问时间
- Linux下如何查看文件秒级修改及访问时间
- Linux文件编码的查看及修改
- linux文件权限查看及修改
- linux 文件编码查看及修改
- linux文件权限查看及修改-chmod
- linux查看及修改文件权限
- linux文件权限查看及修改-chmod
- 演绎手风琴效果
- 【学习C++】学习C++ -> 进一步了解函数
- HDOJ1032 The 3n + 1 problem
- Erasing and Winning UVA
- IOS开发中ARC下的assign和weak区别
- linux 文件时间查看及修改
- JSON.parse()和JSON.stringify()
- 占位图片生成器:holder.js
- Google File System学习笔记
- Java并发编程实战: 线程基本概念
- Centos中更新PHP版本
- Tiny-Spring源码阅读(一)IOC的理解
- angular-cli styles 全局样式引用无效
- moho pro 12中文破解注册激活图文教程 | 含moho pro 12 注册机使用教程