Linux命令集(Linux文件管理命令--touch指令篇)

Linux文件管理命令集(touch指令篇)


如下为笔者总结出在linux中最常用的touch指令集
🌟希望能够帮助正在Linux路上奋斗的你🌟


6. touch(touch)

创建新文件或更新时间戳(修改或创建文件)

touch -a filename.py
#只更新文件的访问时间(atime),不改变修改时间(mtime)
touch -m filename.py
#只更新文件的修改时间(mtime),不改变访问时间(atime)
短选项长选项描述
-a--time=atime只更新文件的访问时间,而不更新修改时间
-c--no-create不创建任何文件
-d--date=time使用指定的日期时间而不是当前时间
-f--force如果文件不存在,则不会创建新文件,而是忽略该错误
-m--time=mtime只更新文件的修改时间,而不更新访问时间
-r--reference=file使用 file 文件的时间戳作为这些被 touch 的文件的时间戳
-t--time=time使用指定的时间而不是当前时间。时间格式为: [[CC]YY]MMDDhhmm[.ss]
-h--no-dereference不会解决符号链接,而是会修改符号链接的时间戳
-v--verbose在更改每个文件的时间戳之前打印文件名
----help显示帮助信息
----version显示版本信息

下述为touch命令详细选项(--help)

Usage: touch [OPTION]... FILE...
Update the access and modification times of each FILE to the current time.

A FILE argument that does not exist is created empty, unless -c or -h
is supplied.

A FILE argument string of - is handled specially and causes touch to
change the times of the file associated with standard output.

Mandatory arguments to long options are mandatory for short options too.
  -a                     change only the access time
  -c, --no-create        do not create any files
  -d, --date=STRING      parse STRING and use it instead of current time
  -f                     (ignored)
  -h, --no-dereference   affect each symbolic link instead of any referenced
                         file (useful only on systems that can change the
                         timestamps of a symlink)
  -m                     change only the modification time
  -r, --reference=FILE   use this file's times instead of current time
  -t STAMP               use [[CC]YY]MMDDhhmm[.ss] instead of current time
      --time=WORD        change the specified time:
                           WORD is access, atime, or use: equivalent to -a
                           WORD is modify or mtime: equivalent to -m
      --help     display this help and exit
      --version  output version information and exit

Note that the -d and -t options accept different time-date formats.

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Full documentation at: <http://www.gnu.org/software/coreutils/touch>
or available locally via: info '(coreutils) touch invocation'

 ***********************************************************
 ***********************************************************
 
使用方法:touch [选项]... 文件...
更新每个文件的访问时间和修改时间为当前时间。

如果提供了-c或-h选项,那么不存在的文件参数将被创建为空文件。

文件参数字符串为“-”时,touch会处理得特殊一些,它将更改与标准输出关联的文件的时间戳。

长选项的必选参数对于短选项也是必选的。
-a                     仅更改访问时间
-c, --no-create        不要创建任何文件
-d, --date=STRING      解析STRING并使用它代替当前时间
-f                     (被忽略)
-h, --no-dereference   影响每个符号链接而不是与之相关联的任何引用文件(仅在可以更改符号链接的时间戳的系统上有用)
-m                     仅更改修改时间
-r, --reference=FILE   使用此文件的时间而不是当前时间
-t STAMP               使用[[CC]YY]MMDDhhmm[.ss]代替当前时间
--time=WORD        更改指定的时间:
WORD是access、atime或use:等同于-a
WORD是modify或mtime:等同于-m
--help             显示此帮助信息并退出
--version          输出版本信息并退出

请注意,-d和-t选项接受不同的日期/时间格式。

GNU核心实用程序在线帮助: http://www.gnu.org/software/coreutils/
完整文档: http://www.gnu.org/software/coreutils/touch
或者通过info '(coreutils) touch invocation'本地获取。

1. 创建名为 file1 的空文件

touch file1

2. 创建名为 file1 和名为 file2 的多个文件

touch file1 file2

3. 创建名为 file1 的文件并将访问时间设置为特定日期

touch -a -t 202201011200 file1

4. 创建名为 file1 的文件并将创建时间和最后修改时间都设置为特定日期

touch -c -t 202201011200 file1

5. 修改名为 file1 的文件的最后修改时间为现在

touch file1

6. 强制更改名为 file1 的文件的修改和访问时间,并创建文件(如果不存在)

touch -cm file1

7. 创建名为 file1 的文件并将其所有时间戳设置为当前完整时间

touch -ca file1

8. 创建名为 file1 的文件并将其所有时间戳设置为十分钟后

touch -d '10 minutes' file1

9. 将多个文件的访问和修改时间设置为名为 file1 的文件的时间戳

touch -r file1 file2 file3


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

是你呀星途

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

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

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

打赏作者

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

抵扣说明:

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

余额充值