Linux touch commands are not commonly used and may be used when using make, to modify the file timestamp, or to create a new file that does not exist.
1. Command format:
touch [Options] ... File...
2. Command parameters:
Only the access time is changed by-A or--time=atime or--time=access or--time=use.
-C or--no-create does not establish any documents.
-D uses the specified date time instead of the current time.
-F This parameter ignores no processing and is responsible for resolving the issue of compatibility of the BSD version of touch instructions only.
-M or--time=mtime or--time=modify only change the change time.
-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 date time instead of the current time.
3. Command function:
The touch command parameter changes the date and time of the document or directory, including the access time and the change time.
4. Use Example:
Instance one: Creating a file that does not exist
Command:
Touch Log2012.log Log2013.log
Output:
[Root@localhost test]# Touch Log2012.log Log2013.log
[Root@localhost test]# LL
-rw-r--r--1 root 0 10-28 16:01 log2012.log
-rw-r--r--1 root 0 10-28 16:01 log2013.log
If Log2014.log does not exist, the file is not created
[Root@localhost test]# touch-c Log2014.log
[Root@localhost test]# LL
-rw-r--r--1 root 0 10-28 16:01 log2012.log
-rw-r--r--1 root 0 10-28 16:01 log2013.log
Instance two: Update Log.log time and Log2012.log time stamp the same
Command:
Touch-r Log.log Log2012.log
Output:
[Root@localhost test]# LL
-rw-r--r--1 root 0 10-28 16:01 log2012.log
-rw-r--r--1 root 0 10-28 16:01 log2013.log
-rw-r--r--1 root 0 10-28 14:48 log.log
[Root@localhost test]# touch-r log.log log2012.log
[Root@localhost test]# LL
-rw-r--r--1 root 0 10-28 14:48 log2012.log
-rw-r--r--1 root 0 10-28 16:01 log2013.log
-rw-r--r--1 root 0 10-28 14:48 log.log
Example three: Set the timestamp of a file
Command:
Touch-t 201211142234.50 Log.log
Output:
[Root@localhost test]# LL
-rw-r--r--1 root 0 10-28 14:48 log2012.log
-rw-r--r--1 root 0 10-28 16:01 log2013.log
-rw-r--r--1 root 0 10-28 14:48 log.log
[Root@localhost test]# touch-t 201211142234.50 log.log
[Root@localhost test]# LL
-rw-r--r--1 root 0 10-28 14:48 log2012.log
-rw-r--r--1 root root 0 10-28 16:01 log2013.log
-rw-r--r--1 root 0 2012-11-14 log.log
Description
-T time uses the value of the specified timestamp as the new value for the appropriate timestamp for the specified file. The time here is defined as a decimal number in the following form:
[[Cc]yy] mmddhhmm[. SS]
Here, the CC is the first two digits of the year, the number of centuries, and yy is the last two digits of the year, the number of years in a century. If you do not give the value of CC, the touch will limit the number of years ccyy within 1969--2068. MM is the number of months, DD for days will be the number of years Ccyy limited within the 1969--2068. MM is the number of months, DD is the number of days, HH for hours (several), MM for minutes, SS for seconds. The set of seconds here is 0--61 so that you can handle leap seconds. These numbers consist of a time in the specified time zone of the environment variable TZ. Due to the limitations of the system, the time earlier than January 1, 1970 is wrong.
View a full set of articles: Http://www.bianceng.cn/OS/Linux/201301/35075.htm