With Touch This command, we can easily modify the date and time of the file, and can also create an empty file. However, it is important to note that even when we copy a file, all properties are copied, but there is no way to copy the CTime property. CTime can record the time when the file's recent state (status) was changed. Anyway, still want to tell everyone, we usually look at the file attributes, the more important or belong to that mtime. What we often care about is when the "content" of this file was changed.
In any case, the most common use of the Touch command is:
Create an empty file;
Modifies a file date to the current date (Mtime and Atime).
Command format:
touch [Options] ... File...
Command parameters:
-A modifies access time only.
-C only modifies the file time and does not create any files.
-D can be used to modify the date instead of the current date, using a variety of different formats.
-F is not used and is reserved for compatibility with other UNIX systems.
-M only changes the change time mtime.
-R Sets the date and time of the specified document or directory to the same date and time as the reference document or directory.
-T uses the specified datetime, rather than the current time, in the same format as the date directive.
command example:
1. Adjust the 123.txt file to the first two days. Current date 2016.4.22
[Email protected] zdw]# lltotal 4-rw-r--r--. 1 root root 4 Apr 16:49 123.txt 22nd [[email protected] zdw]# touch-d "2 days Ago" 123.txt[[email protected] Z dw]# ll 123.txt; ll--time=atime 123.txt; ll--time=ctime 123.txt-rw-r--r--. 1 root root 4 Apr 16:49 123.txt-rw-r--r--. 1 root root 4 Apr 16:49 123.txt-rw-r--r--. 1 root root 4 Apr 16:49 123.txt
The above example, originally 22nd, became the 20th (atime/mtime)
CTime, however, did not follow the change.
2. Change 123.txt date to 2016/4/10 02:03
[Email protected] zdw]# touch-t 1604100203 123.txt [[email protected] zdw]# ll 123. txt ll--time=atime 123.txt; ll--time=ctime 123.txt-rw-r--r--. 1 root root 4 Apr 02:03 123.txt-rw-r--r--. 1 root root 4 Apr 02:03 123.txt-rw-r--r--. 1 root root 4 Apr 16:57 123.txt
The date Atime and mtime have changed, but CTime is the time to record the current.
The 3.-c parameter, if the file does not exist, is not created
[Email protected] zdw]# touch-c 456.txt[[email protected] zdw]# lltotal 4-rw-r--r--. 1 root root 4 Apr 02:03 123.txt
4.-r parameter, update 123.txt time and 456.txt timestamp same, whichever is 123.txt time
[email protected] zdw]# Touch 456.txt[[email protected] zdw]# lltotal 4-rw-r--r--. 1 root root 4 Apr 02:03 123.txt-rw-r--r--. 1 root root 0 Apr 17:03 456.txt[[email protected] zdw]# touch-r 123.txt 456.txt[[email protected] zdw]# lltotal 4-rw-r --r--. 1 root root 4 Apr 02:03 123.txt-rw-r--r--. 1 root root 0 Apr 02:03 456.txt
This article is from the "Zhao Dongwei blog" blog, make sure to keep this source http://zhaodongwei.blog.51cto.com/4233742/1871243
Linux command (+): Touch command