Linux下touch是一个非常有用的命令。

touch语法结构如下:

touch [-acfm][-d <日期时间>][-r <参考文件或目录>][-t <日期时间>][--help]   [--version][文件或目录...] 或 touch [-acfm][--help][--version][日期时间][文件或目录...]

Usage: touch [OPTION]... FILE...
Mandatory arguments to long options are mandatory for short options too.
  -a    change only the access time
  -d, --date=STRING    parse STRING and use it instead of current time
  -m    change only the modification time
  -r, --reference=FILE    use this file's times instead of current time
  -t STAMP    use [[CC]YY]MMDDhhmm[.ss] instead of current time
  --time=WORD    change the specified time:
          WORD is access, atime, or use: equivalent to -a
          WORD is modify or mtime: equivalent to -m
Note that the -d and -t options accept different time-date formats.

使用举例

--------------------------------------------

touch -m -d "2016-05-20 14:25:50" file
touch -d "2016-05-20 14:25:50" file
touch -d "2016-05-20" file
touch -d "14:25:50" file
或者
touch -t 201605201315.50 file
touch -t 05201315 file

命令参数:

-d使用指定的日期时间。
-a只更改存取时间access
-m只更改变动时间modify

设置日期(设置当前时间,只有root权限才能设置,其他只能查看):

#date //显示当前日期
#date -s 20061010 //设置成20061010,这样会把具体时间设置成空00:00:00
#date -s 12:23:23 //设置具体时间,不会对日期做更改
#date -s "2006-10-10 12:12:23" //这样可以设置全部时间

--------------------------------------------

具体步骤

1、设置系统时间(能影响change time)

date -s "2010-10-10 10:10:10"

2、修改文件时间

#当前目录下文件/文件夹(不能递归):

touch -m -d "2010-10-10 10:10:10" *

#递归修改当前目录下所有文件/文件夹3个时间戳(Access、Modify、Change time):

find ./ * -exec touch {} \;

#递归修改当前目录下所有文件/文件夹指定时间戳(Modify、Change time):

find ./ * -exec touch -m -d "2010-10-10 10:10:10" {} \;

3、还原系统时间

clock --hctosys

注意:

1、文件的Access time会随着每次访问而更新时间,所有这个参数意义不大,浏览器每打开一次这个文件,Access time均会更新。

2、Change time不能随便修改,必须先修改系统时间才能改变这个值。

查看系统硬件时钟

clock --show

硬件时钟与系统时钟同步:

clock --hctosys  hc代表硬件时间,sys代表系统时间

PS:补充下查看文件时间:

stat file

时间显示示例:

Access: 2010-05-02 01:22:11.000000000 +0800
Modify: 2010-05-02 01:22:11.000000000 +0800
Change: 2010-10-10 00:00:14.000000000 +0800

linux下修改时间戳的更多相关文章

  1. 【修改端口号】linux下修改apache,nginx服务端口号

    一.linux下修改apache端口号 yum安装后,apache配置文件: /etc/httpd/conf/httpd.conf 找到apache目录下的 httpd.conf, 使用vi 打开,找 ...

  2. 嵌入式 Linux下修改MAC地址

    Linux下修改MAC地址 方法一: 1.关闭网卡设备ifconfig eth0 down2.修改MAC地址ifconfig eth0 hw ether MAC地址3.重启网卡ifconfig eth ...

  3. Linux下修改PATH的方法

    Linux下修改PATH的方法 1.直接在命令行里敲 PATH=$PATH:/path1:/path2:/pathN用户登出之后PATH恢复原样. 只是临时起作用. 2.修改~目录下bash_prof ...

  4. Linux下修改网卡IP、DNS和网关

    Linux下修改网卡IP和网关 建议通过终端字符方式下来修改 一.修改IP地址 vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 BOO ...

  5. linux下修改IP信息

    在Linux的系统下如何才能修改IP信息 以前总是用ifconfig修改,重启后总是得重做.如果修改配置文件,就不用那么麻烦了- A.修改ip地址 即时生效: # ifconfig eth0 192. ...

  6. Linux下修改字符集,转自

    以下转自http://blog.csdn.net/cyuyan112233/article/details/6539122 Linux下修改字符集 locale -a 查询系统支持的字符集 expor ...

  7. Linux 下修改Tomcat使用的JVM内存大小

    我的服务器的配置: # OS specific support.  $var _must_ be set to either true or false. JAVA_OPTS="-Xms10 ...

  8. linux下修改hostid

    linux下修改hostid 网上有很多版本,总结了这几点. 1> 一个以16进制显示的int字符串: 2> 配置文件: /etc/hostid; 如果有值,输出, 结束. 3> 从 ...

  9. linux下修改Apache配置文件

    linux下修改host文件host文件存放路径 /etc/hosts 可以用vim编辑 //Apache配置虚拟主机 /usr/local/apache/conf/extra/httpd-vhost ...

随机推荐

  1. CSS:手机页面,常用字号和布局(工作中用)

    {literal}   {/literal} 公用css .cOrange,.cOrange:visited,.cOrange > a {color: #ff7200;} .border1-to ...

  2. LeetCode 86. Partition List 划分链表 C++

    Given a linked list and a value x, partition it such that all nodes less than x come before nodes gr ...

  3. python url监控 并邮件报警

    import timeimport requestsimport smtplibfrom email.mime.text import MIMETextimport datetime def Send ...

  4. java面试题复习(六)

    51.实现多线程的方法 一种是继承Thread类:另一种是实现Runnable接口.两种方式都要通过重写run()方法来定义线程的行为,推荐使用后者,因为Java中的继承是单继承,一个类有一个父类,如 ...

  5. [PHP]正则表达式判断网址

    来源:https://segmentfault.com/q/1010000000584340/a-1020000000584362 Markdown 的作者之一写的正则表达式(原文在这) (?i)\b ...

  6. github PageHelper使用PageInfo数据错乱问题

    如果出现了数据错乱,检查一下代码是否正确 PageHelper.start(1,10); List<MyEntity> lists = mapper.query(); PageInfo&l ...

  7. python视频学习笔记2(if)

    一.if语句1.比较运算符,if语句语法 # 1. 输入用户年龄# 2. 判断是否满 18 岁 (**>=**)# 3. 如果满 18 岁,允许进网吧嗨皮# 4. 如果未满 18 岁,提示回家写 ...

  8. matrix矩阵变换参数图形化详解

  9. springBoot、SpringCloud 常用注解

    1,@SpringBootApplication是springboot启动类的入口注解,标注在主启动类上:2,@EnableEurekaServer 是eureka服务端启动,接受其他服务注册进来,标 ...

  10. git--创建空的分支

    背景:项目进行中,需要创建一个空分支.在Git中创建分支,是必须有一个父节点的,也就是说必须在已有的分支上来创建新的分支,如果你的工程已经进行了一段时间,这个时候是无法创建空分支的. 解决方法: 使用 ...