← 返回命令列表

Linux command

touch 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Create a new empty file

touch [file]

Create multiple files

touch [file1] [file2] [file3]

Update access and modification time

touch [existing_file]

Set specific modification time

touch -t [[CC]YY]MMDDhhmm[.ss] [file]

Set time from another file

touch -r [reference_file] [file]

Change only access time

touch -a [file]

Change only modification time

touch -m [file]

Do not create file

touch -c [file]

说明

touch updates file access and modification timestamps. If the file doesn't exist, touch creates an empty file (unless -c or -h is specified). Common uses include creating empty files, updating timestamps to trigger make rebuilds, and setting specific times for testing or archival purposes. Time can be specified in several formats: -t for precise timestamps, -d for human-readable strings ("yesterday", "2 hours ago"), or -r to copy times from another file. Without -a or -m, both access time (atime) and modification time (mtime) are updated. Change time (ctime) is always updated by the kernel when timestamps change.

参数

-a
Change only access time
-m
Change only modification time
-c, --no-create
Do not create file if it doesn't exist
-d _string_, --date=_string_
Parse string and use instead of current time
-r _file_, --reference=_file_
Use times from reference file
-t _stamp_
Use timestamp [CCYY]MMDDhhmm.ss instead of current time
-h, --no-dereference
Affect symbolic link instead of referenced file
--time=_WORD_
Change the specified time: _access_, _atime_, _use_ are equivalent to -a; _modify_, _mtime_ are equivalent to -m
-f
Ignored; provided for compatibility with BSD versions of touch

FAQ

What is the touch command used for?

touch updates file access and modification timestamps. If the file doesn't exist, touch creates an empty file (unless -c or -h is specified). Common uses include creating empty files, updating timestamps to trigger make rebuilds, and setting specific times for testing or archival purposes. Time can be specified in several formats: -t for precise timestamps, -d for human-readable strings ("yesterday", "2 hours ago"), or -r to copy times from another file. Without -a or -m, both access time (atime) and modification time (mtime) are updated. Change time (ctime) is always updated by the kernel when timestamps change.

How do I run a basic touch example?

Run `touch [file]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -a do in touch?

Change only access time