当前位置: 首页 > 工具软件 > TouchTime > 使用案例 >

touch

费朗
2023-12-01

touch

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

1. SYNOPSIS

touch [OPTION]... FILE...

2. DESCRIPTION

Update the access and modification times of each FILE to the current time.
将每个 FILE 的访问和修改时间更新为当前时间。

A FILE argument that does not exist is created empty, unless -c or -h is supplied.
除非提供 -c-h,否则将不存在的 FILE 参数设置为空。

A FILE argument string of - is handled specially and causes touch to change the times of the file associated with standard output.
特殊处理 FILE 参数字符串,以更改与标准输出关联的文件的时间。

Mandatory arguments to long options are mandatory for short options too.

mandatory ['mændət(ə)rɪ]:adj. 强制的,托管的,命令的 n. 受托者 (等于 mandatary)

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

DATE STRING
The --date=STRING is a mostly free format human readable date string such as “Sun, 29 Feb 2004 16:21:42 -0800” or “2004-02-29 16:21:42” or even “next Thursday”. A date string may contain items indicating calendar date, time of day, time zone, day of week, relative time, relative date, and numbers. An empty string indicates the beginning of the day. The date string format is more complex than is easily documented here but is fully described in the info documentation.
日期字符串可以包含指示日历日期、时间、时区、星期几、相对时间、相对日期和数字的项目。空字符串表示当天的开始。日期字符串格式比这里容易记录的更复杂,但在 info 文档中有详细描述。

strong@foreverstrong:~/Desktop/makefile_work$ ls -l
total 12
drwxrwxr-x 2 strong strong 4096 Mar 22 14:14 include
drwxrwxr-x 2 strong strong 4096 Mar 22 14:14 lib
drwxrwxr-x 3 strong strong 4096 Mar 22 14:20 src
strong@foreverstrong:~/Desktop/makefile_work$ 
strong@foreverstrong:~/Desktop/makefile_work$ touch include
strong@foreverstrong:~/Desktop/makefile_work$ 
strong@foreverstrong:~/Desktop/makefile_work$ ll
total 20
drwxrwxr-x 5 strong strong 4096 Mar 22 14:14 ./
drwxr-xr-x 8 strong strong 4096 Jun  6 14:29 ../
drwxrwxr-x 2 strong strong 4096 Jun 11 21:58 include/
drwxrwxr-x 2 strong strong 4096 Mar 22 14:14 lib/
drwxrwxr-x 3 strong strong 4096 Mar 22 14:20 src/
strong@foreverstrong:~/Desktop/makefile_work$ 
strong@foreverstrong:~/Desktop/makefile_work$ touch lib
strong@foreverstrong:~/Desktop/makefile_work$ 
strong@foreverstrong:~/Desktop/makefile_work$ ls -l
total 12
drwxrwxr-x 2 strong strong 4096 Jun 11 21:58 include
drwxrwxr-x 2 strong strong 4096 Jun 11 21:58 lib
drwxrwxr-x 3 strong strong 4096 Mar 22 14:20 src
strong@foreverstrong:~/Desktop/makefile_work$ 
strong@foreverstrong:~/Desktop/makefile_work$ touch file
strong@foreverstrong:~/Desktop/makefile_work$ 
strong@foreverstrong:~/Desktop/makefile_work$ ll
total 20
drwxrwxr-x 5 strong strong 4096 Jun 11 21:58 ./
drwxr-xr-x 8 strong strong 4096 Jun  6 14:29 ../
-rw-rw-r-- 1 strong strong    0 Jun 11 21:58 file
drwxrwxr-x 2 strong strong 4096 Jun 11 21:58 include/
drwxrwxr-x 2 strong strong 4096 Jun 11 21:58 lib/
drwxrwxr-x 3 strong strong 4096 Mar 22 14:20 src/
strong@foreverstrong:~/Desktop/makefile_work$

使用指令 touch 修改文件/目录时间属性后,再次查看文件/目录的时间属性。
使用指令 touch 时,如果指定的文件不存在,则将创建一个新的空白文件。在当前目录下,使用该指令创建一个空白文件 file。
touch 命令一般在 make 中,用来修改文件时间戳,或者新建一个不存在的文件。

 类似资料: