hi,欢迎访问本站!
当前位置: 首页操作系统正文

linux 系统中的 touch 命令创建文件

墨初 操作系统 595阅读

在Linux系统中创建一个文件一般都是使用 touch 命令,这也是使用频率比较高的命令,下面73so博客就对touch命令作个详细的介绍。

Linux 中的 touch 命令

touch命令虽然可以创建一个新的文件,但它的命令在特定的场景下发挥的作用不一样。

1、如果需要创建的文件已在,在使用touch命令创建文件时,只会修改文件的时间属性为当前时间,不会修改文件内容。

2、如果需要创建的文件不存在,则会新创建文件

linux touch 创建文件的方法

touch 创建单个文件

命令

touch 文件名

例:

touch config.txt

touch 创建同时创建多个文件

命令

touch 文件名1 文件名2 文件名3 ....

例:

touch config.txt config2.txt config3.txt

touch 批量创建文件

命令

touch 文件创建规则

例:

[root@VM-16-2-centos ~]# touch a{1..5}.txt
[root@VM-16-2-centos ~]# ls
a1.txt  a2.txt  a3.txt  a4.txt  a5.txt

linux touch 修改文件时间

1、touch修改文件时间

touch 如果创建的文件已存在,则会更新文件的时间属性为当前时间,并不会修改文件的内容。

touch 文件名

例:

[root@VM-16-2-centos mochu]# touch a.txt
[root@VM-16-2-centos mochu]# ls -l
总用量 0
-rw-r--r-- 1 root root 0 11月 27 17:28 a.txt
[root@VM-16-2-centos mochu]# touch a.txt
[root@VM-16-2-centos mochu]# ls -l
总用量 0
-rw-r--r-- 1 root root 0 11月 27 17:29 a.txt

2、touch 修改文件创建时间为指定时间

touch -t YYMMDDHHMM.SS 文件名

例:

[root@VM-16-2-centos mochu]# touch -t 202210202030.30 a.txt
[root@VM-16-2-centos mochu]# ls -l
总用量 0
-rw-r--r-- 1 root root 0 11月 27 17:31 202211222020.30
-rw-r--r-- 1 root root 0 10月 20 20:30 a.txt
声明:无特别说明,转载请标明本文来源!
相关推荐