zoukankan      html  css  js  c++  java
  • linux之touch命令修改文件的时间戳

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

    语法:touch   [选项]  文件
    短选项长选项含义
    -a --time=atime
    或--time=access
    或--time=use
    只更改存取时间
    -m --time=mtime
    或--time=modify
    只更改变动时间
    -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@jfht ~]# ls -l new.txt 
    ls: new.txt: 没有那个文件或目录 
    [root@jfht ~]# touch new.txt 
    [root@jfht ~]# ls -l new.txt 
    -rw-r--r-- 1 root root 0 10-11 22:40 new.txt 
    [root@jfht ~]# 
     
     
    更改文件时间为当前时间 
    [root@jfht ~]# ls -l new.txt 
    -rw-r--r-- 1 root root 0 10-11 22:40 new.txt 
    [root@jfht ~]# touch new.txt 
    [root@jfht ~]# ls -l new.txt 
    -rw-r--r-- 1 root root 0 10-11 22:41 new.txt 
     
     
    更改文件时间为指定时间 
    [root@jfht ~]# date 
    2010年 10月 11日 星期一 22:42:54 CST 
    [root@jfht ~]# touch -t 10112200 new.txt   <=== 格式 MMDDhhmm 
    [root@jfht ~]# ls -l new.txt 
    -rw-r--r-- 1 root root 0 10-11 22:00 new.txt 
    [root@jfht ~]# touch -t 200910112200 new.txt   <=== 格式 yyyyMMDDhhmm 
    [root@jfht ~]# ls -l new.txt 
    -rw-r--r-- 1 root root 0 2009-10-11 new.txt 
    [root@jfht ~]# 
     
    [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 
  • 相关阅读:
    cocos2dx学习资源汇总(转)
    Cocos2dx 绘制动画
    Cocosdx中CCMenuItem菜单项进一步介绍
    Cocos2dx中场景切换
    ActionScript3.0 大数据类型
    Cocos2dx 菜单项
    as3.0 Function.apply()与Function.call()方法简介
    Inherited用法代码示例
    区分保留字跟关键字
    标题栏上画按钮代码示例
  • 原文地址:https://www.cnblogs.com/kex1n/p/5266756.html
Copyright © 2011-2022 走看看