谷动谷力

 找回密码
 立即注册
查看: 1233|回复: 0
打印 上一主题 下一主题
收起左侧

Linux创建文件修改目录的时间属性touch命令

[复制链接]
跳转到指定楼层
楼主
发表于 2021-8-14 16:55:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 sunsili 于 2021-8-14 17:18 编辑

touch命令主要有两个功能:
  • 将已存在文件的时间更改为当前系统时间
  • 创建一个空的文件

不会用的命令
首先
  1. touch --help
复制代码


常见参数详解:
-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

参数说明
  • a 改变档案的读取时间记录。
  • m 改变档案的修改时间记录。
  • c 假如目的档案不存在,不会建立新的档案。与 --no-create 的效果一样。
  • f 不使用,是为了与其他 unix 系统的相容性而保留。
  • r 使用参考档的时间记录,与 --file 的效果一样。
  • d 设定时间与日期,可以使用各种不同的格式。
  • t 设定档案的时间记录,格式与 date 指令相同。
  • --no-create 不会建立新档案。
  • --help 列出指令格式。
  • --version 列出版本讯息。
二、实战
#创建一个不存在的空文件,如果存在无影响

  1. #创建一个不存在的空文件,如果存在无影响
  2. touch t1.txt
  3. # 改变文件的时间戳
  4. touch -t 202010091130 t1.txt
  5. ll
  6. -rw-r--r--. 1 root root 4 Oct  9 11:30 t1.txt
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|深圳市光明谷科技有限公司|光明谷商城|Sunshine Silicon Corpporation ( 粤ICP备14060730号|Sitemap

GMT+8, 2024-4-19 15:07 , Processed in 0.149362 second(s), 33 queries .

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表