Linux touch 命令指南大全

1. 概述

在本教程中,我们将学习touch命令。简而言之,这个命令允许我们更新文件或目录的最后修改时间和最后访问时间。

因此,我们将重点关注如何使用该命令及其各种选项。

请注意,我们使用 Bash 测试了此处显示的所有命令;但是,它们应该与任何兼容 POSIX 的 shell 一起使用。

2. 默认行为

通过执行touch,文件系统上的一个或多个文件或目录将被更新,以便将它们的上次修改时间和上次访问时间设置为当前系统时间。

那么,假设今天的日期是 2020 年 2 月 1 日,时间是上午 7:00。

如上所述,该命令将更新example-file.txt文件的两个时间戳:

 ls -l example-file.txt
-rw-r--r--  1 baeldung  baeldung  0 Jan  1 20:00 example-file.txt

# touch example-file.txt

# ls -l example-file.txt
-rw-r--r--  1 baeldung  baeldung  0 Feb  1 07:00 example-file.txtspan>

2.1. 创建新文件

此外,当指定的文件不存在时,该命令将创建一个空文件并相应地设置时间:

 ls -l sample-file.txt
ls: sample-file.txt: No such file or directory

# touch sample-file.txt

# ls -l sample-file.txt
-rw-r--r--  1 baeldung  baeldung  0 Feb  1 07:00 sample-file.txt

如果创建新文件,则新创建文件的权限将默认为给定文件系统的标准权限。

  • 11
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值