In Linux commands, we will often use cd, ls and other commands, but commands like touch are less useful, so what does the touch command do? Let's take a look at the usage of the touch command under Linux with the small series.
linux in touch command is not commonly used, in general may be useful when using the make, the time stamp is used to modify the file or create a file that does not exist.
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 create any documents.
-d Use the specified date and time instead of the current time.
-f This parameter will be ignored and will only be used to resolve compatibility issues with the BSD version of the touch directive.
-m or --time=mtime or --time=modify only changes 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 Use the specified date and time instead of the current time.
3. Command Function:
The touch command parameter changes the date and time of a document or directory, including access time and change time.
4. Example of use:
Example 1: 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 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, then Do not create a file
[root@localhost test]# touch -c log2014.log
[root@localhost 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 2 : Update log.log time is the same as log2012.log timestamp
Command:
touch -r log.log log2012.log
Output:
[root@localhost 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
[root@localhost test]# touch -r log.log Log2012.log
[root@localhost 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
Instance 3: Setting the timestamp of the file
Command:
touch -t 201211142234.50 log.log
Output:
[root@localhost 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
[ Root@localhost test]# touch -t 201211142234.50 log.log
[root@localhost 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 ro Ot root 0 2012-11-14 log.log
Description:
-t time Use the specified time value time as the new value for the corresponding timestamp of the specified file. The time here is defined as a decimal number in the following form:
[[CC]YY]MMDDhhmm[.SS]
Here, CC is the first two digits of the year, ie, ” The number rd is the last two digits of the year, that is, the number of years in a century. If you do not give the value of CC, touch will limit the number of years CCYY to 1969--2068. MM is the number of months, DD is the day will limit the number of years CCYY within 1969--2068. 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, and SS is the number of seconds. Here the setting range of seconds is 0--61, which can handle leap seconds. The time formed by these numbers is one of the time zones specified by the environment variable TZ. Due to system limitations, the time earlier than January 1, 1970 was wrong.
The above is the usage of the touch command under Linux. The touch command can be used to modify the file timestamp. The modified date is the specified date and time instead of the current time. Have you learned it?
Fail2ban is a very useful software, it can monitor the system log, can effectively
We all know that the rm command in the Linux command is mainly used to delete files, then what is th
In the Linux system, the files can be decompressed on the Deepin command line. You can also decompre
To create an RPM package on a Linux system, create a shell script and a readme file
Tips for learning Linux system commands
How to use the CRT command tool to view Linux system resource information
Application of mkdir command in Linux
Ubuntu Unity online search only shows the skills of the terminal application
Linux uses GRUB to add kernel parameters
CentOS python version is too low How to manually upgrade?
Fedora system ifconfig and netstat command can not find a solution
Linux system file permissions and access mode introduction
How Linux expands the number of file openers
Linux viewing system installed kernel operation method
28 examples of Windows XP super application skills
CF shared big coffee and said that young people are not convinced to receive red dragon shovel spree
Win7 notebook quick connection to expand another display method
Windows 7 system camera black screen can not start the reason and solution
Open Win8.1 preview to hide "God mode"
Microsoft urges Win10 users not to give up the Edge browser
How to open blue screen error in win7?
How to close the "Windows File Protection" function of the Win7 system