Linux命令(86)之touch

简介: Linux命令(86)之touch

linux命令之touch

1.touch介绍
linux命令touch是用来创建普通文件,若文件存在,则只修改当前文件的时间

2.touch用法
touch [参数] FileName

touch参数
参数 说明
-r 使用参照文档的时间记录
-d 设置日期与时间,可以使用不同的时间格式
3.实例
3.1.创建ztj.txt文件
命令:

touch ztj.txt

[root@centos79-3 ~]# touch ztj.txt
[root@centos79-3 ~]# ls -l ztj.txt
-rw-r--r-- 1 root root 0 Sep 13 09:16 ztj.txt
[root@centos79-3 ~]#
3.2.参照/etc/passwd文件的时间记录,创建aa.txt
命令:

touch -r /etc/passwd aa.txt

[root@centos79-3 ~]# touch -r /etc/passwd aa.txt
[root@centos79-3 ~]# ls -l aa.txt
-rw-r--r-- 1 root root 0 Sep 8 20:03 aa.txt
[root@centos79-3 ~]# ls -l /etc/passwd
-rw-r--r-- 1 root root 835 Sep 8 20:03 /etc/passwd
[root@centos79-3 ~]#
3.3.把*.sh脚本时间更改为2023/9/11
命令:

touch -d "9/11/2023" *.sh

[root@centos79-3 ~]# touch -d "9/11/2023" .sh
[root@centos79-3 ~]# ls -l
.sh
-rwxr-xr-x 1 root root 3109 Sep 11 00:00 basic_init.sh
-rwxr-xr-x 1 root root 84 Sep 11 00:00 check_nginx.sh
-rwxr-xr-x 1 root root 22 Sep 11 00:00 date.sh
[root@centos79-3 ~]#
3.4.同时创建多个文件
命令:

touch {1..10}.txt

[root@centos79-3 ~]# touch {1..10}.txt
[root@centos79-3 ~]# ls -l *.txt
-rw-r--r-- 1 root root 0 Sep 13 09:20 10.txt
-rw-r--r-- 1 root root 0 Sep 13 09:20 1.txt
-rw-r--r-- 1 root root 0 Sep 13 09:20 2.txt
-rw-r--r-- 1 root root 0 Sep 13 09:20 3.txt
-rw-r--r-- 1 root root 0 Sep 13 09:20 4.txt
-rw-r--r-- 1 root root 0 Sep 13 09:20 5.txt
-rw-r--r-- 1 root root 0 Sep 13 09:20 6.txt
-rw-r--r-- 1 root root 0 Sep 13 09:20 7.txt
-rw-r--r-- 1 root root 0 Sep 13 09:20 8.txt
-rw-r--r-- 1 root root 0 Sep 13 09:20 9.txt

————————————————
版权声明:本文为CSDN博主「小黑要上天」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/z19861216/article/details/132845101

目录
相关文章
|
3天前
|
Linux
Linux的cp命令如何使用?
Linux的cp命令如何使用?
11 5
|
7天前
|
Linux
Linux常用命令包括
Linux常用命令包括
16 5
|
7天前
|
Linux
Linux命令
Linux命令
18 5
|
3天前
|
安全 Linux Shell
常见的 Linux 命令大全(表格形式)
常见的 Linux 命令大全(表格形式)
|
11天前
|
Linux Python Perl
Linux命令删除文件里的字符串
Linux命令删除文件里的字符串
26 7
|
11天前
|
Shell Linux
Linux shell编程学习笔记82:w命令——一览无余
Linux shell编程学习笔记82:w命令——一览无余
|
13天前
|
Linux Perl
Linux之sed命令
Linux之sed命令
|
13天前
|
Linux
深入理解Linux中的cp命令:文件与目录的复制利器
深入理解Linux中的cp命令:文件与目录的复制利器
|
13天前
|
Linux Docker 容器
9. 同步执行Linux多条命令
9. 同步执行Linux多条命令
|
13天前
|
Linux Shell
10-10|linux命令查询 关键字在文本中出现的行数
10-10|linux命令查询 关键字在文本中出现的行数