English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Linux touch command

Linux Command大全

The Linux touch command is used to modify the time 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 file's time records.

Syntax

touch [-acfm][-d<date time>][-r<reference file or directory>] [-t<date time>][--help][--version][File or directory…]
  • Parameter Description:
  • a Changes the file's read time record.
  • m Changes the file's modification time record.
  • c If the target file does not exist, a new file will not be created. --no-create has the same effect.
  • f is retained for compatibility with other Unix systems.
  • r Uses the time record of the reference file, and --file Has the same effect.
  • d Sets the time and date, which can be formatted in various ways.
  • t Sets the file's time record, in the same format as the 'date' command.
  • --no-create Does not create a new file.
  • --help Lists command formats.
  • --version Prints version information.

Online Examples

Use the command 'touch' to modify the time attributes of the file 'testfile' to the current system time, enter the following command:

$ touch testfile                # Modify the file's time attributes 

First, use the 'ls' command to view the attributes of the 'testfile' file, as shown below:

$ ls -l testfile                # View the file's time attributes  
# The original file's modification time was16:09  
-rw-r--r-- 1 hdd hdd 55 2011-08-22 16:09 testfile  

After executing the command 'touch' to modify the file attributes and then checking the file's time attributes again, as shown below:

$ touch testfile                # Modify the file's time attributes to the current system time  
$ ls -l testfile                # View the file's time attributes  
# The file's time attributes are modified to the current system time after the modification  
-rw-r--r-- 1 hdd hdd 55 2011-08-22 19:53 testfile  

When using the command 'touch', if the specified file does not exist, a new blank file will be created. For example, to create a blank file 'file' in the current directory, enter the following command:

$ touch file            # Create a new blank file named 'file' 

Linux Command大全