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. C#实现多个PDF合并及去除文字水印功能

    实现pdf合并就是使用Spire.Pdf.dll类库的方法,但是注意需要同时引用Spire.Pdf.dll和Spire.License.dll两个类库,且两个类库的版本要一致 String[] fil ...

  2. QMap迭代器

    QMap<int, QString> intToStr; intToStr[] = "test" for (auto iter = intToStr.begin(); ...

  3. NumPy基础

    一.NumPy ndarray (一)生成ndarray 表 数组生成函数 函数 描述(默认数据类型是float64) array 将输入数据(序列型对象)转换为ndarray,若不显示的指定数据类型 ...

  4. IDEA 常用插件

    Maven Helperp3pauto filling Java call argumentsCamelCaseVisualVM LauncherTranslation.ignoreGenerateA ...

  5. Ubuntu安装后上网问题,

    首先VMware网络配置详解一:三种网络模式简介 http://www.cnblogs.com/gylei/archive/2012/04/06/2435087.html 很详细. 此处讲述通过桥接来 ...

  6. JVM内存模型和面试题解析

    一.JVM运行时区域 其中, 线程私有的:程序计数器,虚拟机栈,本地方法栈 线程共享的:堆,方法区,直接内存 1 程序计数器 程序计数器是一块较小的内存空间,可以看作是当前线程所执行的字节码的行号指示 ...

  7. mysql 线程操作

    show processlist;//查询mysql所有连接线程 SELECT CONCAT('KILL ',id,';') FROM information_schema.`PROCESSLIST` ...

  8. 【396】python 递归练习题(COMP9021)

    Merging two strings into a third one Say that two strings s1 and s2 can be merged into a third strin ...

  9. 在树莓派3B、Ubuntu 18.04关闭板载Wifi、蓝牙

    树莓派没有传统的BIOS设置界面,文件/boot/firmware/config.txt就相当一个BIOS设置.这里是config.txt的详细文档:https://github.com/raspbe ...

  10. 从 TFS 迁移源代码到 git

    准备工具: https://github.com/git-tfs/git-tfs 具体的安装步骤上面的 readme.md 中有说明.通过 Chocolatey 安装,如果本地没有 git ,会自动安 ...