今天是:
带着程序的旅程,每一行代码都是你前进的一步,每个错误都是你成长的机会,最终,你将抵达你的目的地。
title

touch命令

touch 命令用于修改文件或者目录的时间属性,包括存取时间和更改时间。若文件不存在,系统会建立一个新的文件。

语法

touch [OPTION]... FILE...

主要用途

  • 创建空白文件: 最常见的用途是创建新的空白文件。如果指定的文件不存在,touch 命令将会创建一个名为指定文件名的空白文件。这对于快速创建占位符文件、空白配置文件或测试文件非常有用。

  • 更新文件时间戳touch 命令还可以用于更新文件的访问时间(atime)和修改时间(mtime)戳。通过执行 touch 命令,你可以将一个现有文件的时间戳更新为当前时间,而不实际更改文件内容。这在一些特定情况下很有用,例如在需要监视文件的访问时间时。

  • 批量创建多个文件touch 命令可以一次创建多个文件,只需在命令后列出多个文件名即可。这对于需要批量创建多个文件的情况非常方便。

  • 创建文件并指定时间戳: 使用 touch 命令,你可以创建一个文件并同时指定它的访问时间和修改时间。这可以通过 -t 选项来完成。

参数说明:

  • a:或--time=atime或--time=access或--time=use 只更改存取时间;
  • -c:或--no-create 不建立任何文件;
  • -d:<时间日期> 使用指定的日期时间,而非现在的时间;
  • -f:此参数将忽略不予处理,仅负责解决BSD版本touch指令的兼容性问题;
  • -m:或--time=mtime或--time=modify 只更该变动时间;
  • -r:<参考文件或目录> 把指定文件或目录的日期时间,统统设成和参考文件或目录的日期时间相同;
  • -t:<日期时间> 使用指定的日期时间,而非现在的时间;
  • --help:在线帮助;
  • --version:显示版本信息。

-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.

实例

touch filename.txt    创建一个txt文件

touch -c filename.txt  更新文件的修改时间为当前时间

touch file1.txt file2.txt file3.txt  一次性创建多个文件

touch -t 202310260930.00 filename.txt 设置或修改文件时间戳

 

分享到:

专栏

类型标签

网站访问总量