当前位置: 首页 > news >正文

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

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

  • Linux文件管理命令集(touch指令篇)
    • 6. touch(touch)
      • 1. 创建名为 file1 的空文件
      • 2. 创建名为 file1 和名为 file2 的多个文件
      • 3. 创建名为 file1 的文件并将访问时间设置为特定日期
      • 4. 创建名为 file1 的文件并将创建时间和最后修改时间都设置为特定日期
      • 5. 修改名为 file1 的文件的最后修改时间为现在
      • 6. 强制更改名为 file1 的文件的修改和访问时间,并创建文件(如果不存在)
      • 7. 创建名为 file1 的文件并将其所有时间戳设置为当前完整时间
      • 8. 创建名为 file1 的文件并将其所有时间戳设置为十分钟后
      • 9. 将多个文件的访问和修改时间设置为名为 file1 的文件的时间戳

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 referencedfile (useful only on systems that can change thetimestamps 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 -aWORD is modify or mtime: equivalent to -m--help     display this help and exit--version  output version information and exitNote 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


http://www.lryc.cn/news/64198.html

相关文章:

  • 软件工程学习教程大纲
  • 使用ChatGPT生成了十种排序算法
  • GEE:MODIS计算遥感指数(NDVI、BSI、NDSI、EVI、LSWI、SIPI、EBI等)
  • 《*** 法治思想学习纲要》学习辅导
  • 初识Go语言18-面向对象【面向对象的概念、构造函数、继承与重写 泛型】
  • 4.微服务项目实战---Sentinel--服务容错
  • Postgres SELECT INSERT 流程 ?
  • OpenAI推企业版ChatGPT,英伟达造AI安全卫士
  • 【原创】运维的终点是开发~chatGPT告诉你真相
  • SSH 服务器、NFS 服务器、TFTP 服务器详解及测试
  • 1.3 HBase 基本架构
  • 微机作业题
  • 非极大值抑制详细原理(NMS含代码及详细注释)
  • 女朋友说总是记不住Git命令,怎么办?安排!
  • 【ChatGLM】本地版ChatGPT ?6G显存即可轻松使用 !ChatGLM-6B 清华开源模型本地部署教程
  • 【MySQL】练习六 关系数据理论及数据库设计
  • UG NX二次开发(C++)-建模-修改NXObject或者Feature的颜色(一)
  • 全球天气weather.com的icon汇总表 天气现象代码枚举
  • 【Python】【进阶篇】16、settings.py配置文件详解
  • 【华为机试】HJ1 字符串最后一个单词的长度
  • Spring DI简介及依赖注入方式和依赖注入类型
  • ES6栈方法和队列方法
  • EventBus(事件总线)的使用和源码的简单解析
  • 《汇编语言》- 读书笔记 - 第2章-寄存器
  • English Learning - L3 综合练习 1 VOA-Color 2023.04.26 周三
  • 50道web前端工程师面试题及答案解析,你学会了吗
  • 【链表OJ题 1】反转链表
  • 【华为OD机试真题】计算网络信号 (javaC++python)100%通过率 超详细代码注释
  • Tomcat8和Tomcat9乱码问题
  • Lesson13 IP协议