资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

touch修改文件时间或者创建文件

功能:对已经存在文件的时间进行修改,存取时间(access time)、修改时间(modification time)。对不存在的文件,进行创建新的空白文件。

创新互联是网站建设专家,致力于互联网品牌建设与网络营销,专业领域包括成都做网站、网站设计、外贸营销网站建设、电商网站制作开发、微信小程序、微信营销、系统平台开发,与其他网站设计及系统开发公司不同,我们的整合解决方案结合了恒基网络品牌建设经验和互联网整合营销的理念,并将策略和执行紧密结合,且不断评估并优化我们的方案,为客户提供全方位的互联网品牌整合方案!

短选项长选项含义
-a–time=atime
或–time=access
或–time=use
只更改存取时间
-m–time=mtime只更改变动时间
-d TIME–-date=字符串设定时间与日期,可以使用各种不同的格式
-t STAMP
设定时间戳。STAMP是十进制数: [[CC]YY]MMDDhhmm[.SS]
CC为年数中的前两位,即”世纪数”;YY为年数的后两位,即某世纪中的年数。如果不给出CC的值,则touch将把年数CCYY限定在1969–2068之内。
MM为月数,DD为天将把年数CCYY限定在1969–2068之内.MM为月数,DD为天数,hh 为小时数(几点),mm为分钟数SS为秒数.此处秒的设定范围是0–61,这样可以处理闰秒。
这些数字组成的时间是环境变量TZ指定的时区中的一个时间。由于系统的限制,早于1970年1月1日的时间是错误的
-r FILE
把指定文档或目录的日期时间,统统设成和参考文档或目录的日期时间相同
-c–no-create不建立任何文档

Linux的多个time属性
access time是文档最后一次被读取的时间。因此阅读一个文档会更新它的access时间,但它的modify时间和change时间并没有变化。cat、more 、less、grep、sed、tail、head这些命令都会修改文件的access时间。 
change time是文档的索引节点(inode)发生了改变(比如位置、用户属性、组属性等)。chmod, chown,create,mv等动作会将Linux文件的change time修改为系统当前时间。
modify time是文本本身的内容发生了变化。[文档的modify时间也叫时间戳(timestamp).] ls命令看到的是modify time。用vi等工具编辑一个文件保存后,modify time会被修改。

创建新文件 
[root@GChan ~]# ls -l new.txt 
ls: new.txt: 没有那个文件或目录 
[root@GChan ~]# touch new.txt 
[root@GChan ~]# ls -l new.txt 
-rw-r--r-- 1 root root 0 10-11 22:40 new.txt 
[root@GChan ~]# 
 
 
更改文件时间为当前时间 
[root@GChan ~]# ls -l new.txt 
-rw-r--r-- 1 root root 0 10-11 22:40 new.txt 
[root@GChan ~]# touch new.txt 
[root@GChan ~]# ls -l new.txt 
-rw-r--r-- 1 root root 0 10-11 22:41 new.txt 
 
 
更改文件时间为指定时间 
[root@GChan ~]# date 
2010年 10月 11日 星期一 22:42:54 CST 
[root@GChan ~]# touch -t 10112200 new.txt   <=== 格式 MMDDhhmm 
[root@GChan ~]# ls -l new.txt 
-rw-r--r-- 1 root root 0 10-11 22:00 new.txt 
[root@GChan ~]# touch -t 200910112200 new.txt   <=== 格式 yyyyMMDDhhmm 
[root@GChan ~]# ls -l new.txt 
-rw-r--r-- 1 root root 0 2009-10-11 new.txt 
[root@GChan ~]# 
 
[root@localhost test]# ll 
-rw-r--r-- 1 root root    0 10-28 14:48 log2012.log 
-rw-r--r-- 1 root root    0 10-28 16:01 log2013.log 
-rw-r--r-- 1 root root    0 10-28 14:48 log.log 
[root@localhost test]# touch -t 201211142234.50 log.log   201211142234.50时间戳  
[root@localhost test]# ll 
-rw-r--r-- 1 root root    0 10-28 14:48 log2012.log 
-rw-r--r-- 1 root root    0 10-28 16:01 log2013.log 
-rw-r--r-- 1 root root    0 2012-11-14 log.log 
 
将 file 的时间记录改成 5 月 6 日 18 点 3 分,公元两千年。时间可以使用 am, pm 或是 24 小时的格式,日期可以使用其他格式如 6 May 2000。 
touch -d "6:03pm" file 
touch -d "05/06/2000" file 
touch -d "6:03pm 05/06/2000" file 
 
 
将文件时间改成与别的文件相同 
[root@localhost test]# ll 
-rw-r--r-- 1 root root    0 10-28 16:01 log2012.log 
-rw-r--r-- 1 root root    0 10-28 16:01 log2013.log 
-rw-r--r-- 1 root root    0 10-28 14:48 log.log 
[root@localhost test]# touch -r log.log log2012.log  
[root@localhost test]# ll 
-rw-r--r-- 1 root root    0 10-28 14:48 log2012.log 
-rw-r--r-- 1 root root    0 10-28 16:01 log2013.log 
-rw-r--r-- 1 root root    0 10-28 14:48 log.log

标题名称:touch修改文件时间或者创建文件
新闻来源:http://cdkjz.cn/article/giegde.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220