RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
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

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


新闻名称:touch修改文件时间或者创建文件-创新互联
文章转载:http://scyingshan.cn/article/ppocj.html