Linux 指令篇:档案目录管理--touch

2016-01-29 19:37 0 1 收藏

Linux 指令篇:档案目录管理--touch,Linux 指令篇:档案目录管理--touch

【 tulaoshi.com - Linux 】

  名称:touch

使用权限:所有使用者

使用方式: 
touch [-acfm] 
[-r reference-file] [--file=reference-file] 
[-t MMDDhhmm[[CC]YY][.ss]] 
[-d time] [--date=time] [--time={atime,access,use,mtime,modify}] 
[--no-create] [--help] [--version] 
file1 [file2 ...] 


说明: 
touch 指令改变档案的时间记录。 ls -l 可以显示档案的时间记录。 


参数:
a 改变档案的读取时间记录。 
m 改变档案的修改时间记录。 
c 假如目的档案不存在,不会建立新的档案。与 --no-create 的效果一样。 
f 不使用,是为了与其他 unix 系统的相容性而保留。 
r 使用参考档的时间记录,与 --file 的效果一样。 
d 设定时间与日期,可以使用各种不同的格式。 
t 设定档案的时间记录,格式与 date 指令相同。 
--no-create 不会建立新档案。 
--help 列出指令格式。 
--version 列出版本讯息。 


范例:


最简单的使用方式,将档案的时候记录改为现在的时间。若档案不存在,系统会建立一个新的档案。



 touch file
touch file1 file2 
 


将 file 的时间记录改为 5 月 6 日 18 点 3 分,公元两千年。时间的格式可以参考 date 指令,至少需输入 MMDDHHmm ,就是月日时与分。 



 touch -c -t 05061803 file
touch -c -t 050618032000 file 
 


将 file 的时间记录改变成与 referencefile 一样。 



 touch -r referencefile file 
 


将 file 的时间记录改成 5 月 6 日 18 点 3 分,公元两千年。时间可以使用 am, pm 或是 24 小时的格式,日期可以使用其他格式如 6 May 2000 。


 touch -d "6:03pm" file
touch -d "05/06/2000" file
touch -d "6:03pm 05/06/2000" file 




 touch 也可以制造一个空档(0 byte).例如DHCP Server所需的/etc/dhcpd.leases,dhcpd 必须要有这个档案才能运作正常.[root@/root]#touch /etc/dhcpd.leases[root@/root]#ls -l /etc/dhcpd.leases-rw-r--r-- 1 root root 0 Jul 3 05:50 /etc/dhcpd.leases


记得上一次重灌前把/etc下的设定档tar起来,重灌好之后把原有设定还原,却发现系统检查设定档的时间有问题,这个时候用
 find /etc -name * -exec touch {}; 
 
就可以把设定档的时间更新到与现在一致了。 

来源:https://www.tulaoshi.com/n/20160129/1509802.html

延伸阅读
  名称:less 使用权限:所有使用者 使用方式:   less [Option] filename    说明:         less 的作用与 more 十分相似,都可以用来浏览文字档案的内容,不同的是 less 允许使用者往回卷动     ...
  名称 : cd 使用权限 : 所有使用者 使用方式 : cd [dirName] 说明 : 变换工作目录至 dirName。 其中 dirName 表示法可为绝对路径或相对路径。若目录名称省略,则变换至使用者的 home directory (也就是刚 login 时所在的目录)。 另...
  名称:cp 使用权限:所有使用者 使用方式: cp [options] source dest cp [options] source... directory 说明:将一个档案拷贝至另一档案,或将数个档案拷贝至另一目录。 参数:  -a 尽可能将档案状态、权限等资料都照原状予以复制。 -r 若 source 中含有目录名...
  指令名称 : ln 使用权限 : 所有使用者 使用方式 : ln [options] source dist,其中 option 的格式为 : [-bdfinsvF] [-S backup-suffix] [-V {numbered,existing,simple}] [--help] [--version] [--] 说明 : Linux/Unix&n...
名称:cut 使用权限:所有使用者 用法:cut -cnum1-num2 filename 说明:显示每行从开头算起 num1 到 num2 的文字。 范例: shell>> cat example test2 this is test1 shell>> cut -c0-6 example ## print 开头算起前 6 个字元 test2 this i cut其实很有用 -c m-n 表示显示每一行的第m个字元到第n个字元。例如: --------...

经验教程

278

收藏

69
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部