Summary command-touch
Touch command is a very common command to create text, many people tend to ignore its parameters, and its parameter function is still very useful.
Touch command parameters
-an or-- time=atime or-- time=access or-- time=use changes the read time record of the file.
-c or-- no-create does not create any documentation.
-d uses the specified date time instead of the current time.
-f this parameter is ignored and not processed, and is only responsible for resolving the compatibility issue of the BSD version of the touch directive.
-m or-- time=mtime or-- time=modify changes the modification time of the file.
-r set 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 date time instead of the current time
Example:
1. Create a file
# touch a.txt
(ls-- full-time)
-rw-r--r-- 1 svnuser svnuser 0 2015-04-21 10 purl 45 a.txt 39.141783261 + 0800
2. Modify the time when the file was created and last modified
# touch-t 201404200900 a.txt
-rw-r--r-- 1 svnuser svnuser 0 2014-04-20 09 a.txt 00.000000000 + 0800 a.txt
3. Modify the time of the specified file to be the same as another file
# touch-r a.txt b.txt / / change the file modification time of b.txt to the same as that of a.txt file
-rw-r--r-- 1 svnuser svnuser 0 Apr 21 10:53 a.txt
-rw-r--r-- 1 svnuser svnuser 0 Apr 21 10:53 b.txt
4. B.txt time can be modified by am,pm or 24-hour time system.
# touch-d "6:03pm" b.txt
-rw-r--r-- 1 svnuser svnuser 0 2015-04-21 18 purl 03purl 00.000000000 + 0800 b.txt
5. Create an empty file
# touch-c c.txt