This command can be used to change the time attributes of a file or directory, including access time and modification time. If the file does not exist, a new file is created. What we usually use most is to create an empty file through touch. In fact, the atime and mtime of the file can be modified through the touch command, so the real access time and modification time of the file can be modified. We also need to do this when troubleshooting system abnormalities. Make comprehensive decisions based on factors such as logs and historical commands.
[root@s145]~# touch --help
[root@s145]~# touch --version
touch (GNU coreutils) 8.22
…
If the file does not exist, use the touch command to create an empty file by default.
Use the touch command. If the file exists, update atime, mtime, and ctime to the current time.
Use the -a parameter. When touching the file, if the file exists, only atime and ctime will be updated to the current time.
Use the -m parameter. When touching a file, only mtime and ctime will be updated to the current time if the file exists.
Use the option -d "3 years ago" of the touch command. Set the three timestamps of the file to 3 years ago.
Use touch -t "[[CC]YY] MMDDhhmm[.ss]"Modify the atime and mtime of the file
If you only want to update the atime, you can use - at combination parameters.
If you only want to update mtime, you can use the -mt combination parameter.
Use the touch command and specify the file1 file as a reference. You can change the file2 file The time attribute value of is updated to the same value as file1. The specific command is: touch -r file1 file2.
The touch command updates the time attribute of the real file by default. If you need to update the time of the soft link, Attribute, you need to use the -h parameter.
Usage: touch [OPTION]… FILE&hellip ;
Parameter | Parameter description |
---|---|
- a | Change the file's read time record. |
-c | If the destination file does not exist, a new file will not be created. Same effect as --no-create. |
-d | Set the time and date in various formats. |
-f | is not used and is reserved for compatibility with other unix systems. |
-h | Affects each symlink, not any referenced file (only useful on systems where symlink timestamps can be changed) |
-m | Change the modification time record of the file. |
-r | Use the time record of the reference file, which has the same effect as --file. |
-t | Set the time record of the file, the format is the same as the date command. |
–help | Lists the command format. |
–version | List version information. |
The above is the detailed content of How to use Linux touch command. For more information, please follow other related articles on the PHP Chinese website!