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
[root@centos79-3 ~]# 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小黑要上天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值