Linux touch commands are not commonly used, and are generally used when using make, to modify file timestamps, or to create a new file that does not exist.
The touch command has two functions: one is to update the time tags of existing files to the current time of the system (the default), their data will remain intact, and the second is to create new empty files.
1. Command format:
touch [Options] ... File...
2. Command parameters:
-A or--time=atime or--time=access or--time=use only change the access time.
-C or--no-create does not establish any documents.
-D < time date > Use the specified date time instead of the current time.
-F This parameter ignores non-processing and is responsible only for compatibility issues with BSD version touch directives.
-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:< Date Time > Use the specified datetime, not the current time;
--help: Online Help;
--version: Displays version information.
3. Command function:
The touch command parameter changes the date time of the document or directory, including access time and change time.
4. Examples of Use:
Instance one: Create a file that does not exist
Command:
Touch Log2012.log Log2013.log
Output:
[email protected] test]# Touch Log2012.log Log2013.log
[email protected] test]# LL
-rw-r--r--1 root root 0 10-28 16:01 log2012.log
-rw-r--r--1 root root 0 10-28 16:01 log2013.log
If Log2014.log does not exist, the file is not created
[Email protected] test]# touch-c Log2014.log
[email protected] test]# LL
-rw-r--r--1 root root 0 10-28 16:01 log2012.log
-rw-r--r--1 root root 0 10-28 16:01 log2013.log
Instance two: Update Log.log time and Log2012.log timestamp same
Command:
Touch-r Log.log Log2012.log
Output:
[email protected] test]# LL
-rw-r--r--1 root root 0 10-28 16:01 log2012.log
-rw-r--r--1 root root 0 10-28 16:01 log2013.log
-rw-r--r--1 root root 0 10-28 14:48 log.log
[Email protected] test]# touch-r log.log log2012.log
[email protected] test]# LL
-rw-r--r--1 root 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 root 0 10-28 14:48 log.log
Example three: Setting the timestamp of a file
Command:
Touch-t 201211142234.50 Log.log
Output:
[email protected] test]# LL
-rw-r--r--1 root 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 root 0 10-28 14:48 log.log
[Email protected] test]# touch-t 201211142234.50 log.log
[email protected] test]# LL
-rw-r--r--1 root 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 root 0 2012-11-14 log.log
Description
-T time uses the value specified as a new value for the corresponding time stamp of the specified file. The time specified here is a decimal number in the following form:
[[Cc]yy] mmddhhmm[. SS]
Here, CC is the first two digits of the number of years, that is, "century"; yy is the last two digits of the number of years, that is, the number of years in a century. If the value of CC is not given, touch will limit the number of years Ccyy to 1969--2068. MM for the number of months, DD for the day will be the number of years Ccyy limited to 1969--2068 within. MM is the number of months, DD is the number of days, HH is the number of hours (several), MM is the number of minutes, SS is the number of seconds. The set range of seconds here is 0--61, which can handle leap seconds. These numbers consist of a time in the time zone specified by the environment variable TZ. Due to system limitations, the time earlier than January 1, 1970 was wrong.
I used the touch command:
Touch fileName: Create an empty file.
Touch-t yyyymmddhhmm. SS fileName: Creates a file at a specific time.
Linux Learning Note 8--command touch