功能:对已经存在文件的时间进行修改,存取时间(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 

linux之touch命令修改文件的时间戳的更多相关文章

  1. Linux使用touch批量修改文件/文件夹时间戳

      Linux下touch是一个非常有用的命令. touch语法结构如下: touch [-acfm][-d <日期时间>][-r <参考文件或目录>][-t <日期时间 ...

  2. linux下vi命令修改文件及保存的使用方法

    进入vi的命令 vi filename :打开或新建文件,并将光标置于第一行首 vi n filename :打开文件,并将光标置于第n行首 vi filename :打开文件,并将光标置于一行首 v ...

  3. (转)linux下vi命令修改文件及保存的使用方法

    进入vi的命令         vi filename :打开或新建文件,并将光标置于第一行首    vi n filename :打开文件,并将光标置于第n行首    vi filename :打开 ...

  4. linux下用命令修改文件内容

    修改test_modify.sh中的LICENSE_INFO test_modify.sh #!/bin/bash licenseInfo=LICENSE_INFO licenseProduct=LI ...

  5. Linux中用stat命令查看文件时3个时间点解析

    有些时候,我们需要在Linux中使用stat命令来查看文件的详细信息.另外联想下,ls -l命令显示的是什么时间,touch命令修改文件的时间戳,修改的又是什么时间?在这里我们一起来试验下. 首先,我 ...

  6. linux中touch命令参数修改文件的时间戳(转)

    linux中touch命令参数不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存在的文件,以下是linux中touch命令参数的使用方法: touch [-acm][-r ...

  7. linux中touch命令参数修改文件的时间戳(转载)

    转自:http://os.51cto.com/art/200908/144237.htm linux中touch命令参数不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存 ...

  8. Linux命令:修改文件权限命令chmod、chgrp、chown详解

    Linux系统中的每个文件和目录都有访问许可权限,用它来确定谁可以通过何种方式对文件和目录进行访问和操作. 文件或目录的访问权 限分为只读,只写和可执行三种.以文件为例,只读权限表示只允许读其内容,而 ...

  9. Linux chmod命令修改文件与文件夹权限的命令附实例

    Linux chmod命令修改文件与文件夹权限的命令附实例 作者:佚名 字体:[增加 减小] 来源:互联网 时间:05-01 20:46:07我要评论 在linux中要修改一个文件夹或文件的权限我们需 ...

随机推荐

  1. Eclipse Jetty调试时无法保存js文件

    Jetty会使用内存映射文件来缓存静态文件,包括js,css文件. 在Windows下,使用内存映射文件会导致文件被锁定,所以当Jetty启动的时候无法在编辑器对js或者css文件进行编辑. 解决办法 ...

  2. 河南省第十届省赛 Plumbing the depth of lake (模拟)

    title: Plumbing the depth of lake 河南省第十届省赛 题目描述: There is a mysterious lake in the north of Tibet. A ...

  3. Nginx的主要配置参数说明

    #定义Nginx运行的用户和用户组user www www; #nginx进程数,建议设置为等于CPU总核心数.worker_processes 8; #全局错误日志定义类型,[ debug | in ...

  4. 【git】git提交忽略不必要的文件或文件夹

    对于经常使用Git的朋友来说,.gitignore配置一定不会陌生.废话不说多了,接下来就来说说这个.gitignore的使用. 首先要强调一点,这个文件的完整文件名就是".gitignor ...

  5. (五)对linux内核中jiffies+Hz表示一秒钟的理解

    jiffies在内核中是一个全局变量,它用来统计系统启动以来系统中产生的总节拍数,这个变量定义在include/Linux/jiffies.h中,定义形式如下. unsigned long volat ...

  6. Linux中生成Core Dump系统异常信息记录文件的教程

    Linux中生成Core Dump系统异常信息记录文件的教程 http://www.jb51.net/LINUXjishu/473351.html

  7. 【 Linux 网络虚拟化 】Openvswitch

    openvswitch:    openvswitch: 开放的虚拟交换机,虚拟交换就是利用虚拟平台,通过软件的方式形成交换机部件.跟传统的物理交换机相比,虚拟交换机同样具备众多优点:         ...

  8. xshell命令大全

    suse linux 常用命令 (1)命令ls——列出文件 ls -la 给出当前目录下所有文件的一个长列表,包括以句点开头的“隐藏”文件 ls a* 列出当前目录下以字母a开头的所有文件 ls -l ...

  9. WCF测试小程序

    using System;using System.Collections.Generic;using System.Linq;using System.Runtime.Serialization;u ...

  10. Tomcat的类加载机制

     一个功能健全的Web服务器,要解决如下几个问题: 部署在同一个服务器上的两个Web应用程序使用的Java 类库可以实现相互隔离.不能要求一个类库在一个服务器中只有一份,服务器应当保证两个应用程序的类 ...