[root@linuxtechi ~]# stat sysadm-20.txt File: ‘sysadm-20.txt' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd00h/64768d Inode: 67324189 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:admin_home_t:s0 Access: 2010-02-07 20:15:12.000000000 +0530 Modify: 2010-02-07 20:15:12.000000000 +0530 Change: 2018-03-30 10:23:31.584000000 +0530 Birth: -
注意:在上述命令中,如果我们不指定 -c ,如果系统中不存在该文件那么 touch 命令将创建一个新文件,并将时间戳设置为命令中给出的。
示例:8 使用参考文件设置时间戳(-r)
在 touch 命令中,我们可以使用参考文件来设置文件或目录的时间戳。假设我想在 devops.txt 文件上设置与文件 sysadm-20.txt 文件相同的时间戳, touch 命令中使用 -r 选项可以轻松实现。
语法:
# touch -r {参考文件} 真正文件
[root@linuxtechi ~]# touch -r sysadm-20.txt devops.txt
示例:9 在符号链接文件上更改访问和修改时间
默认情况下,每当我们尝试使用 touch 命令更改符号链接文件的时间戳时,它只会更改原始文件的时间戳。如果你想更改符号链接文件的时间戳,则可以使用 touch 命令中的 -h 选项来实现。
语法:
# touch -h {符号链接文件}
[root@linuxtechi opt]# ls -l /root/linuxgeeks.txt lrwxrwxrwx. 1 root root 15 Mar 30 10:56 /root/linuxgeeks.txt -> linuxadmins.txt [root@linuxtechi ~]# touch -t 203010191820 -h linuxgeeks.txt [root@linuxtechi ~]# ls -l linuxgeeks.txt lrwxrwxrwx. 1 root root 15 Oct 19 2030 linuxgeeks.txt -> linuxadmins.txt
这就是本教程的全部了。我希望这些例子能帮助你理解 touch 命令。以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易采站长站。








