Linux touch 命令使用介绍
Linux touch 命令使用介绍
本文给大家介绍了一些touch命令的用法。touch一般用来创建一个新文件。同时,touch还可以用来修改文件时间戳。
创建新文件:
$ ls -l /tmp/foo ls: /tmp/foo: No such file or directory $ touch /tmp/foo $ ls -l /tmp/foo -rw-r--r-- 1 andy wheel 0 Jul 10 11:56 /tmp/foo
touch还可以用来修改文件时间戳。
-t 参数可以指定要修改成的具体时间
$ ls -l /tmp/foo ls: /tmp/foo: No such file or directory $ touch -t 201107010930 /tmp/foo $ ls -l /tmp/foo -rw-r--r-- 1 andy wheel 0 Jul 1 09:30 /tmp/foo
若没有指定,则设置为当前时间:
$ ls -l /tmp/foo -rw-r--r-- 1 andy wheel 0 Jul 1 09:30 /tmp/foo $ touch /tmp/foo $ ls -l /tmp/foo -rw-r--r-- 1 andy wheel 0 Jul 10 11:58 /tmp/foo
You can also use the timestamp from another file and apply it to another file by using the -r switch.
$ ls -l /tmp/someotherfile -rw-r--r-- 1 andy wheel 0 Aug 12 2005 /tmp/someotherfile $ touch -r /tmp/someotherfile /tmp/foo /tmp/foo2 /tmp/foo3 $ ls -al /tmp/ -rw-r--r-- 1 andy wheel 0 Aug 12 2005 /tmp/foo -rw-r--r-- 1 andy wheel 0 Aug 12 2005 /tmp/foo2 -rw-r--r-- 1 andy wheel 0 Aug 12 2005 /tmp/foo3 -rw-r--r-- 1 andy wheel 0 Aug 12 2005 /tmp/someotherfile
评论暂时关闭