Linux touch command
The Linux touch command is used to modify the time attributes of a file or directory, including access time and modification time. If the file does not exist, the system will create a new file.
ls -l can display the time record of a file.
Syntax
touch [-acfm][-d<日期时间>][-r<参考文件或目录>] [-t<日期时间>][--help][--version][文件或目录…]
- Parameter Description:
- a Change the file's access time record.
- m Change the file's modification time record.
- c If the target file does not exist, no new file will be created. Same effect as --no-create.
- f Not used; kept for compatibility with other Unix systems.
- r Use the time record of a reference file, same effect as --file.
- d Set the time and date; various formats can be used.
- t Set the file's time record, in the same format as the date command.
- --no-create Does not create a new file.
- --help List the command format.
- --version List version information.
Example
To use the "touch" command to change the time attribute of the file "testfile" to the current system time, enter the following command:
$ touch testfile #修改文件的时间属性
First, use the ls command to view the attributes of the testfile file, as follows:
$ ls -l testfile #查看文件的时间属性
#The original file modification time was 16:09
-rw-r--r-- 1 hdd hdd 55 2011-08-22 16:09 testfile
After executing the "touch" command to modify the file attributes, view the file's time attributes again, as follows:
$ touch testfile #修改文件时间属性为当前系统时间
$ ls -l testfile #查看文件的时间属性
#Set the file's timestamp to the current system time
-rw-r--r-- 1 hdd hdd 55 2011-08-22 19:53 testfile
When using the "touch" command, if the specified file does not exist, a new empty file will be created. For example, in the current directory, to create an empty file named "file" with this command, enter the following command:
$ touch file #创建一个名为“file”的新的空白文件
Linux Command Reference