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
linux之touch命令修改文件的时间戳的更多相关文章
- Linux使用touch批量修改文件/文件夹时间戳
Linux下touch是一个非常有用的命令. touch语法结构如下: touch [-acfm][-d <日期时间>][-r <参考文件或目录>][-t <日期时间 ...
- linux下vi命令修改文件及保存的使用方法
进入vi的命令 vi filename :打开或新建文件,并将光标置于第一行首 vi n filename :打开文件,并将光标置于第n行首 vi filename :打开文件,并将光标置于一行首 v ...
- (转)linux下vi命令修改文件及保存的使用方法
进入vi的命令 vi filename :打开或新建文件,并将光标置于第一行首 vi n filename :打开文件,并将光标置于第n行首 vi filename :打开 ...
- linux下用命令修改文件内容
修改test_modify.sh中的LICENSE_INFO test_modify.sh #!/bin/bash licenseInfo=LICENSE_INFO licenseProduct=LI ...
- Linux中用stat命令查看文件时3个时间点解析
有些时候,我们需要在Linux中使用stat命令来查看文件的详细信息.另外联想下,ls -l命令显示的是什么时间,touch命令修改文件的时间戳,修改的又是什么时间?在这里我们一起来试验下. 首先,我 ...
- linux中touch命令参数修改文件的时间戳(转)
linux中touch命令参数不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存在的文件,以下是linux中touch命令参数的使用方法: touch [-acm][-r ...
- linux中touch命令参数修改文件的时间戳(转载)
转自:http://os.51cto.com/art/200908/144237.htm linux中touch命令参数不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存 ...
- Linux命令:修改文件权限命令chmod、chgrp、chown详解
Linux系统中的每个文件和目录都有访问许可权限,用它来确定谁可以通过何种方式对文件和目录进行访问和操作. 文件或目录的访问权 限分为只读,只写和可执行三种.以文件为例,只读权限表示只允许读其内容,而 ...
- Linux chmod命令修改文件与文件夹权限的命令附实例
Linux chmod命令修改文件与文件夹权限的命令附实例 作者:佚名 字体:[增加 减小] 来源:互联网 时间:05-01 20:46:07我要评论 在linux中要修改一个文件夹或文件的权限我们需 ...
随机推荐
- shell正则表达式(1)
一.什么是正则 正则就是用一些具有特殊含义的符号组合到一起(称为正则表达式)来描述字符或者字符串的方法.或者说:正则就是用来描述一类事物的规则. 二.grep 1.参数 -n :显示行号 -o : ...
- 关于flume的几道题
1,要求:监听一个tcp,udp端口41414将数据打印在控制台 # example.conf: A single-node Flume configuration # Name the compon ...
- POJ 3617 Best Cow Line (模拟)
题目链接 Description FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of the Yea ...
- 逐步实现python版wc命令
Python 如何处理管道输入输出 sys.stdin 等于打开了一个文件对象,所有输入的文件都会写入到标准输入文件中(键盘) sys.stdout 等于打来了一个文件对象,使用.write()把信息 ...
- Python3安装cx_Oracle连接oracle数据库实操总结
弄清版本,最重要!!! 首先安装配置时,必须把握一个点,就是版本一致!包括:系统版本,python版本,oracle客户端的版本,cx_Oracle的版本,然后安装配置就容易了! 如果已经安装Pyth ...
- 1.flask视图和URL
1.第一个flask程序 from flask import Flask ''' Flask这个类是项目的核心,以后很多操作都是基于这个类的对象 注册URL等等,都是基于这个类 ''' app = F ...
- 【python】抄写大神的糗事百科代码
照着静觅大神的博客学习,原文在这:http://cuiqingcai.com/990.html 划重点: 1. str.strip() strip函数会把字符串的前后多余的空白字符去掉 2. resp ...
- [ubuntu] service apache2 restart [fail]
$ /etc/init.d/apache2 restart * Restarting web server apache2 [fail] 解决办法4步走: 1. sudo /etc/init.d/ap ...
- CF A.Mishka and Contest【双指针/模拟】
[链接]:CF/4892 [题意]: 一个人解决n个问题,这个问题的值比k小, 每次只能解决最左边的或者最右边的问题 解决了就消失了.问这个人能解决多少个问题. [代码]: #include<b ...
- 高效mysql的习惯(程序员版本)
高效的mysql 一定要有主键 如果没有主键: 数据多次读写后可能更离散,有更多随机I/O MySQL复制环境中,如果选择RBR模式,没有主键的update需要读全表,导致复制延迟 好的主键特点: 没 ...