touch
将文件的访问时间和修改时间修改为当前时间。如果指定的文件不存在,那么将会创造空文件,除非指定-c或-h选项。文件参数字符串‘-‘被专门处理,并导致touch更改与标准输出相关联的文件的时间。
此命令的适用范围:RedHat、RHEL、Ubuntu、CentOS、SUSE、openSUSE、Fedora。
1
、语法
touch [
选项] file
2
、选项列表
选项
|
说明
|
--help
|
显示帮助文档
|
--version
|
显示版本信息
|
-a
|
只改变访问时间
|
-c | --no-create
|
不创建文件
|
-d | --date=time
|
设置为指定的时间,而不是当前的时间
|
-f
|
忽略
|
-h
|
只改变符号链接
|
-m
|
只改变修改时间
|
-r | --reference=file
|
使用指定文件的时间
|
-t
|
使用CCYYMMDDhhmmss时间
|
--time=WORD
|
改指定的时间:Word为access、atime或use
|
“--date=STRING”是一种主要自由格式的人类可读的日期字符串,例如“Sun,2月29日16:21:42-0800”或“2004-02-29 16:21:21:42”,甚至“下星期四”。日期字符串可能包含指示日历日期、日时间、时区、周中日、相对时间、相对日期和数字的项。空字符串表示一天的开始。
3
、实例
1
)创建文件
[root@localhost weijie]#
ls //
文件不存在
1.c 1.c~ 2.c 3.c 4.c 4.c~ 5.c Tsplitaa Tsplitab Tsplitac Tsplitad xaa xab xac
[root@localhost weijie]#
touch -c 6.c //
使用选项
-c
,不创建文件
[root@localhost weijie]#
ls
1.c 1.c~ 2.c 3.c 4.c 4.c~ 5.c Tsplitaa Tsplitab Tsplitac Tsplitad xaa xab xac
[root@localhost weijie]#
touch 6.c //
不使用任何选项,创建文件
[root@localhost weijie]#
ls
1.c 1.c~ 2.c 3.c 4.c 4.c~ 5.c 6.c Tsplitaa Tsplitab Tsplitac Tsplitad xaa xab xac
|
2
)用指定的文件来修改目标文件时间
[root@localhost weijie]#
ll 1.c 2.c //
查看文件时间
-rwxr--r-- 1 root david 50 9
月
14 10:07 1.c
-rwxr--r-- 1 root root 11 9
月
13 16:52 2.c
[root@localhost weijie]#
touch -r 2.c 1.c //
将
1.c
的时间修改和
2.c
一样
[root@localhost weijie]#
ll 1.c 2.c //
查看文件时间
-rwxr--r-- 1 root david 50 9
月
13 16:52 1.c
-rwxr--r-- 1 root root 11 9
月
13 16:52 2.c
|
做了一个Linux学习的平台,目前出来一个雏形,各位可以参考使用
链接:
https://pan.baidu.com/s/1GOLVU2CbpBNGtunztVpaCQ
密码:n7bk