linux命令之touch
linux命令touch是用来创建普通文件,若文件存在,则只修改当前文件的时间
touch [参数] FileName
| 参数 | 说明 |
| -r | 使用参照文档的时间记录 |
| -d | 设置日期与时间,可以使用不同的时间格式 |
命令:
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 ~]#
命令:
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 ~]#
命令:
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 ~]#
命令:
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
- [root@centos79-3 ~]#