touch命令创建文件,很少用

1.命令格式:

touch【参数】文件名

2.命令参数:

      -a更改访问时间        

      -c创建不存在的文件               

      -m更改修改时间                  

      -t指定文件的时间

      -r【文件】使用指定文件时间更新文件时间


3.命令功能:

touch命令参数可更改文档或目录的日期时间,包括修改时间和访问时间。 

4.使用范例:

创建不存在文档:

touch -c

[root@two data]# touch -c a.txt
[root@two data]# ls
text.txt

touch -a

更新访问时间

[root@two data]# ls -l
total 0
-rw-r--r--. 1 root root 0 Jan  5 13:16 text.txt
[root@two data]# ls -lu
total 0
-rw-r--r--. 1 root root 0 Jan  5 13:22 text.txt


[root@two data]# touch -a /data/text.txt
[root@two data]# ls
text.txt
[root@two data]# ls -l
total 0
-rw-r--r--. 1 root root 0 Jan  5 13:16 text.txt
[root@two data]# ls -lu
total 0
-rw-r--r--. 1 root root 0 Jan  5 13:26 text.txt
[root@two data]# 

更新修改时间

[root@two data]# touch -m text.txt
[root@two data]# ls -l
total 0
-rw-r--r--. 1 root root 0 Jan  5 13:32text.txt
[root@two data]# ls -lu
total 0
-rw-r--r--. 1 root root 0 Jan  5 13:26 text.txt
[root@two data]# ls -l
total 0
-rw-r--r--. 1 root root 0 Jan  5 13:35 text.txt
[root@two data]# ls -lu
total 0
-rw-r--r--. 1 root root 0 Jan  5 13:26 text.txt

touch -r

指定文件更新文件的时间

[root@two data]# touch 1.txt
[root@two data]# ls -l 1.txt
-rw-r--r--. 1 root root 0 Jan  5 13:38 1.txt
[root@two data]# touch -r text.txt 1.txt
[root@two data]# ls -l
total 0
-rw-r--r--. 1 root root 0 Jan  5 13:35 1.txt
-rw-r--r--. 1 root root 0 Jan  5 13:35 text.txt
[root@two data]# ls -l 1.txt
-rw-r--r--. 1 root root 0 Jan  5 13:35 1.txt

touch -t

指定时间更新文件

[root@two data]# touch -t 02020202 1.txt
[root@two data]# ls -l 1.txt
-rw-r--r--. 1 root root 0 Feb  2  2015 1.txt