Linux touch Command

Linux 命令大全Linux Command Reference

The Linux touch command is used to modify the timestamp attributes of files or directories, including access time and modification time. If the file does not exist, the system will create a new file.

ls -l can display the timestamp records of files.

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, a new file will not be created. Same effect as --no-create.
  • f Not used; retained for compatibility with other Unix systems.
  • r Use the reference file's timestamp, same effect as --file.
  • d Set the time and date; various formats can be used.
  • t Set the file's timestamp; the format is the same as the date command.
  • --no-create Will not create a new file.
  • --help List the command format.
  • --version Display version information.

Examples

Use the "touch" command to modify the timestamp attributes 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 shown below:

$ ls -l testfile                #查看文件的时间属性  
#原来文件的修改时间为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, check the file's timestamp attributes again, as shown below:

$ touch testfile                #修改文件时间属性为当前系统时间  
$ ls -l testfile                #查看文件的时间属性  
#修改后文件的时间属性为当前系统时间  
-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, to create an empty file named "file" in the current directory using this command, enter the following:

$ touch file            #创建一个名为“file”的新的空白文件 

Linux 命令大全Linux Command Reference

Other Extensions