Linux is used in Linux systems to create files or to modify the timestamp of a file
Command function:
Create an empty file, or modify the timestamp of an existing file
Syntax parameters:
-A or--time=atime or--time=access or--time=use only change access time
-C or--no-create does not create any files.
-d< Time Date > Use the specified datetime, not the current time.
-M or--time=mtime or--time=modify only change the modified time
-r< reference file or directory > set the date and time of the specified file or directory to the same date and time as the reference file or directory.
-t< Date Time > Use the specified datetime instead of the current time
-help Help Documentation
-version displaying version information
Command format: Touch [option] filename
Common examples:
Example 1: Create a file that does not exist.
Command:
Touch 1.txt
Output: Plus parameter-C does not create the file
[[email protected] test]# Touch 1.txt 2.txt 3.txt [[email protected] test]# ls 1.txt 2.txt 3.txt [[email protected] Test ]# touch-c 4.txt [[email protected] test]# ls 1.txt 2.txt 3.txt [[email protected] test]#
Example Two: Modify the last modified time of the existing file to current.
Command:
Touch Install.log
Output:
[email protected] ~]# ll install.log-rw-r--r--. 1 root root 34961 June 22:02 Install.log[[email protected] ~]# touch Install.log[[email protected] ~]# ll INSTALL.LOG-RW -r--r--. 1 root root 34961 June 15:17 Install.log[[email protected] ~]#
Example Three: Modify the timestamp of the install.log.syslog to the timestamp of the Install.log.
Command:
Touch-r Install.log Install.log.syslog
Output:
[email protected] ~]# ll Install.log install.log.syslog-rw-r--r--. 1 root root 34961 June 15:17 Install.log-rw-r--r--. 1 root root 7346 June 21:59 Install.log.syslog[[email protected] ~]# touch-r install.log install.log.syslog [[Email PR Otected] ~]# ll Install.log install.log.syslog-rw-r--r--. 1 root root 34961 June 15:17 Install.log-rw-r--r--. 1 root root 7346 June 15:17 Install.log.syslog[[email protected] ~]#
Example four: Setting the timestamp of the file, setting the Install.log.syslog file timestamp to bit 03211111
Command:
Touch-t 03211111 Install.log.syslog
Output:
[email protected] ~]# ll install.log.syslog-rw-r--r--. 1 root root 7346 June 15:17 Install.log.syslog[[email protected] ~]# touch-t 03211111 install.log.syslog [email Protec Ted] ~]# ll Install.log.syslog-rw-r--r--. 1 root root 7346 Mar 11:11 install.log.syslog[[email protected] ~]#
One Linux command per day-touch