shell学习四十二天----使用touch更新文件时间
来源:互联网 发布:js点击按钮执行ctrl c 编辑:程序博客网 时间:2024/06/07 09:59
使用touch更新文件时间
$ll new.txt
保证输出:ls: 无法访问new.txt: 没有那个文件或目录
$touch new.txt
$ll new.txt
-rw-r--r-- 1 root root 0 7月 12 16:56 new.txt
如果此文件已经存在的情况下.更改文件时间为当前时间
$touch new.txt
-rw-r--r-- 1 root root 0 7月 12 16:57 new.txt
案例:更改文件时间为指定时间
$date
2015年 07月 12日 星期日 16:59:10 CST
$touch -t 11111111 new.txt
$ll new.txt
-rw-r--r-- 1 root root 0 11月 11 2015 new.txt
分析:此处指定文件的时间格式为:yyyy(年)MM(月)DD(日)hh(时)mm(分),省略在表示使用当前系统的时间.
案例:将文件改正与别的文件相同的时间
$ll new.txt
-rw-r--r-- 1 root root 0 7月 12 17:03 new.txt
$ll /etc/passwd
-rw-r--r-- 1 root root 1804 6月 10 23:27 /etc/passwd
$touch -r /etc/passwd new.txt
$ll new.txt
-rw-r--r-- 1 root root 0 6月 10 23:27 new.txt
总结:linux中touch命令参数不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存在的文件.
语法:touch [-acdmt] 文件参数
$find /tmp -exec touch -t 11111111 {} \;
$ll /tmp
总用量 12
drwxr-xr-x 2 root root 4096 11月 11 2015 hidden
-rw-r--r-- 1 root root 0 11月 11 2015 new.txt
drwxr-xr-x 2 root root 4096 11月 11 2015 test
-rwxr-xr-x 1 root root 385 11月 11 2015 touch.sh
分析:可把/tmp下的所有文件和目录都改变修改时间。
主要选项和作用
参数
作用
-a
仅修改文件的最后访问时间
-c
仅修改时间,而不创建文件
-d
后面可以接日期,也可以使用-date=”如期或时间”
-m
仅修改文件的修改时间
-t
后面可接时间,格式为[yyyyMMDDhhmm]
- shell学习四十二天----使用touch更新文件时间
- shell使用汇总3——修改文件时间与创建新文件:touch
- touch 更新多级目录时间
- linux 使用 touch 修改文件的修改时间
- 更新文件find -name "*.c"|xargs touch
- Linux目录递归touch更新文件日期
- linux更新文件命令touch详解
- touch的用法(新建文件,修改时间)
- linux touch更改文件时间戳
- linux touch 修改文件的时间戳
- [Linux] 文件时间属性及touch命令
- touch 修改文件的时间戳
- 获取文件更新时间
- 多学一点(九)——使用touch命令创建指定时间的文件
- linux shell使用tar 备份时间命名的文件
- 使用shell脚本恢复修改文件的时间戳
- 【touch】改变文件或者目录时间的时间戳
- JavaScript学习笔记(四十二) 工厂
- ROS学习手记 - 2.1: Create and Build ROS Package 生成包(Python)
- error:#5:cannotopensourceinputfile"stm32f10x_lib.h":Nosuchfileordirectory
- 每个对象都有自己的由其他对象所构成的存储
- search for a range
- 【线段树】 HDOJ 5283 Senior's Fish
- shell学习四十二天----使用touch更新文件时间
- HDU 2199 二分查找
- [leetcode] 147.Insertion Sort List
- 交换排序之冒泡排序
- XJTU Summer Holiday Test 1(Divisibility by Eight-8的倍数)
- 最短路径—Dijkstra算法和Floyd算法
- Spark
- 快速使用svn仓库
- cocos2dx三角函数与小球