linux 修改文件的时间属性
二、修改文件时间
创建文件我们可以通过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: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2012-07-13 16:21:50.000000000 +0800
Modify: 2012-07-13 16:21:50.000000000 +0800
Change: 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 profile
cp:是否覆盖“./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.log
2. 只修改文件的修改时间
touch -m -d "2010-05-31 08:10:30" install.log
3. 只修改文件的访问时间
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
最后总结下常用的文件操作与时间的关系:
1、访问时间,读一次这个文件的内容,这个时间就会更新。比如对这个文件使用more命令。ls、stat命令都不会修改文件的访问时间。
2、修改时间,对文件内容修改一次,这个时间就会更新。比如:vim后保存文件。ls -l列出的时间就是这个时间。
3、状态改变时间。通过chmod命令更改一次文件属性,这个时间就会更新。查看文件的详细的状态、准确的修改时间等,可以通过stat命令 文件名
linux 修改文件的时间属性的更多相关文章
- linux中文件的时间属性atime/mtime/ctime
文件的时间属性的概念 上图第7-9是时间,默认是ctime(文件修改时间),有三种时间属性: modify time mtime (文件内容被修改的时间) change ti ...
- 在Delphi中获取和修改文件的时间
转载自 http://www.cnblogs.com/jieke/archive/2013/01/11/2855782.html 本文介绍了在Delphi中利用系统函数和Windows API函数调用 ...
- Qt下如何修改文件的时间(全平台修改)
提供一个全平台修改文件的时间的方法,希望大家喜欢 /* UTIME.C: This program uses _utime to set the * file-modification time to ...
- touch - 修改文件的时间戳记.
总览 touch [-acm][-r ref_file(参照文件)|-t time(时间值)] file(文件名)... 被废弃的版本: touch [-acm][ugly_time] file(文件 ...
- linux修改文件所属的用户组以及用户
linux修改文件所属的用户组以及用户 将文件夹从A用户(huangxf)目录复制B用户(zhenglf)目录,其中B没有sudo权限.将A的Downloads文件夹下的所有文件,复制到B的Docum ...
- linux 修改文件时间
1.ls -l *.sh 2.touch -d "10/13/2013" *.sh [我想把所以的.sh文件修改到三个月前(2013年10月13)的时间.]3.ls -l *.sh ...
- Linux指令--文件和目录属性
对于每一个Linux学习者来说,了解Linux文件系统的目录结构,是学好Linux的至关重要的一步.,深入了解linux文件目录结构的标准和每个目录的详细功能,对于我们用好linux系统只管重要,下面 ...
- Linux 修改文件和文件夹权限
查看当前目录和文件权限 ls -l 文件属性 连接数 文件拥有者 所属群组 文件大小 文件修改时间 文件名drwxr-xr-x 4 william wheel 136 Apr 10 23:34 ven ...
- linux修改文件所有者和文件所在组
chgrp 用户名 文件名 -R chown 用户名 文件名 -R -R表示递归目录下所有文件 以上部分已验证 一.修改文件所属组群——chgrp 修改文件所属组群很简单-c ...
随机推荐
- C#用Call代替CallVirt之后的测试用例
一. C# 原始代码和直接结果 测试 C# 代码: class Program { static void Main(string[] args) { A c1 = new C(); c1.Foo() ...
- PlayJava Day006
今日所学: /* 2019.08.19开始学习,此为补档. */ 构造方法没有返回值(即return为空). this:实例(对象)的引用. JVM:①static方法区:存静态数据 ②栈区:引用 ...
- fwrite(): send of 8192 bytes failed with errno=104 Connection reset by peer
问题:fwrite(): send of 8192 bytes failed with errno=104 Connection reset by peer 问题描述 通过mysql + sphinx ...
- zabbix4.0搭建1
server端:负责接受到客户端发送过来的数据,并且保存到自己的数据库当中 端口:10051 agent端:负责每隔一定时间进行客户端的数据采集,并且发送给server端 端口:10050 proxy ...
- MySQL 部署分布式架构 MyCAT (四)
分片(水平拆分) 2.取模分片(mod-long) cd /data/mycat/conf cp schema.xml schema.xml.rang-long vi schema.xml <? ...
- requests---requests发送xml数据类型
上一篇简单的介绍了post常见的4种数据类型,今天我们一起学习通过requests发送xml数据类型 xml数据类型 下方数据为xml数据,我们就通过这段数据学习如果通过requests发送xml数据 ...
- xampp配置虚拟域名
首先使用notpad++(我用的notpad++,记事本也可以)打开(安装xampp目录下的)apach-->conf-->extra-->httpd-vhosts.conf 在文件 ...
- python session保持登录,新增地址,并删除,由观察可知,address_id决定删除的内容;
import requests,reheaders={"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) Ap ...
- win10安装配置mongodb
1. 下载MongoDB并安装官网下载地址:https://blog.csdn.net/qq_41127332/article/details/80755595 ,选择合适的版本进行下载.我选择是3. ...
- 【转】理解并设计rest/restful风格接口
网络应用程序,分为前端和后端两个部分.当前的发展趋势,就是前端设备层出不穷(手机.平板.桌面电脑.其他专用设备......). 因此,必须有一种统一的机制,方便不同的前端设备与后端进行通信.这导致AP ...