Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux touch command

Linux touch command

Linux Command Reference Linux Command Reference

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][文件或目录…]

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 Linux Command Reference