Linux之touch修改或创建文件与目录指令
touch命令用于修改文件或者目录的时间属性,包括存取时间和更改时间。若文件不存在,系统会建立一个新的文件。
命令格式
touch [OPTION] ... FILE ...
touch 创建文件,文件不存在,则新建一个文件。如果文件本身已经存在,那么会修改文件的时间。
例子
touch可以创建文件,文件存在则修改时间
[root@localhost ~]# ll
-rw-------. 1 root root 1233 5月 25 17:00 anaconda-ks.cfg
[root@localhost ~]# touch abc.log
[root@localhost ~]# ll
总用量 4
-rw-r--r--. 1 root root 0 5月 31 04:49 abc.log
-rw-------. 1 root root 1233 5月 25 17:00 anaconda-ks.cfg
[root@localhost ~]# touch abc.log
[root@localhost ~]# ll
总用量 4
-rw-r--r--. 1 root root 0 5月 31 04:50 abc.log
-rw-------. 1 root root 1233 5月 25 17:00 anaconda-ks.cfg
touch,无法创建单独目录(1),但是可以修改文件夹的时间(2)
(1)touch无法创建单个目录
[root@localhost ~]# ll
总用量 4
-rw-------. 1 root root 1233 5月 25 17:00 anaconda-ks.cfg
[root@localhost ~]# touch ccc
[root@localhost ~]# ll
总用量 4
-rw-------. 1 root root 1233 5月 25 17:00 anaconda-ks.cfg
-rw-r--r--. 1 root root 0 5月 31 05:01 ccc
[root@localhost ~]# cd ccc
-bash: cd: ccc: 不是目录
[root@localhost ~]#
(2)修改文件夹时间
[root@localhost ~]# ll
总用量 4
-rw-------. 1 root root 1233 5月 25 17:00 anaconda-ks.cfg
[root@localhost ~]# mkdir ccc
[root@localhost ~]# ll
总用量 4
-rw-------. 1 root root 1233 5月 25 17:00 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 5月 31 05:03 ccc
[root@localhost ~]# touch ccc
[root@localhost ~]# ll
总用量 4
-rw-------. 1 root root 1233 5月 25 17:00 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 5月 31 05:04 ccc
[root@localhost ~]#