Linux使用touch批量修改文件/文件夹时间戳
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使用touch批量修改文件/文件夹时间戳的更多相关文章
- java实现批量修改指定文件夹下所有后缀名的文件为另外后缀名的代码
java实现批量修改指定文件夹下所有后缀名的文件为另外后缀名的代码 作者:Vashon package com.ywx.batchrename; import java.io.File; import ...
- Linux命令行批量替换多文件中的字符串【转】
Linux命令行批量替换多文件中的字符串[转自百度文库] 一种是Mahuinan法,一种是Sumly法,一种是30T法分别如下: 一.Mahuinan法: 用sed命令可以批量替换多个文件中的字符串. ...
- 批量修改mp3文件的title等
批量修改mp3文件的title等 不是改文件名哦: 下载地址:https://mp3tag.en.softonic.com/ 帮助文档:file:///C:/Program%20Files%20(x8 ...
- 【风马一族_windom】 批量修改相同文件类型的后缀
难题:有时因为某种原因,修改一堆文件的类型,重复操作次数多,浪费时间也跟着多,收获也会相当少. 提问:对于软件而言,可量化的,有规律的操作,可以使用程序来进行替代. 特性:在微软操作系统上,不同后缀的 ...
- 批量修改java文件的包名
需求:我复制进批量的java文件,但是包名需要用现在创建的包名 导入进来时,由于包名不一致会报错 解决办法,点击包名鼠标右键>Refactor>Rename 结果如下ok:
- 按模板批量修改Excel文件内容
Sub 按模板修改Excel文件() Dim MoBanWorkBook As Workbook Set MoBanWorkBook = Application.ActiveWorkbook Dim ...
- linux rename命令批量修改文件名
修改文件名可以用mv命令来实现 mv filename1 filename2 1 但如果批量修改还是使用rename命令更为方便 现在我们有a b c d 四个文件 增加后缀 rename 's/$/ ...
- linux '--stdin'错误 -批量修改密码
虚拟机:VMware虚拟机 系统:Linux ubuntu 4.4.0-31-generic #50~14.04.1-Ubuntu SMP Wed Jul 13 01:07:32 UTC 2016 ...
- linux下C++遍历文件夹下的全部文件;Windows/Linux下C++批量修改文件名,批量删除文件
Linux下 C++遍历目录下所有文件 rename(image_path.c_str(), image_path_new.c_str()); remove(image_path_move.c_str ...
随机推荐
- conductor编译镜像
# git clone https://github.com/Netflix/conductor.git # git checkout -b 2.0 remotes/origin/2.0 # cd s ...
- vc for python2.7
https://www.microsoft.com/en-us/download/confirmation.aspx?id=44266
- Failed to acquire connection "SAP_PRD_NEW.SAPSR3". Connection may not be configured correctly or you may not have the right permissions
SQLSERVER JOB无法执行 错误提示: Message Executed as user: WORKGROUP\NSDZHSCMFP01$. Microsoft (R) SQL Server ...
- uwsgi+nginx+django生产环境部署
1.升级python到2.7版本 2.安装uwsgi 出现uwsgi未找到 yum groupinstall "Development tools"yum install zlib ...
- jenkin 不必要的Execute shell执行失败,导致jenkins都失败的解决
问题:jenkins里配置了多个执行shell,且有后续的执行job任务.但其中一个Execute shell执行失败了导致后续的shell都不执行了 而这个失败的shell并不是一定要执行 解决 ...
- logic:equal 标签的使用(转)
<logic:equal name="music" property="distrubute" value="true"> ...
- php71
yum -y install php-mcrypt libmcrypt libmcrypt-devel autoconf freetype gd jpegsrc libmcrypt libpng li ...
- elk6快速安装
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch [elasticsearch-6.x] name=Elasticsear ...
- 94. Binary Tree Inorder Traversal(Tree, stack)
Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary tre ...
- F - Restoring the Expression CodeForces - 898F
字符串hash: base设置为10 枚举'='可能出现的位置,从1/2处开始到大概1/3处结束,当然大概的1/3不用计算,直接到最后就行,因为本题必然有解,输出直接结束即可. 根据'='号位置,' ...