ArticleDirectory
- Parameters
- Option
- Example
- Tips
File Creation or modification time
Touch [Options]File-list
Parameters
File-listYesTouchPath Name of the file to be created or updated
Option
-A only updates the access time without changing the modification time.
-C. Do not create a nonexistent file
-M: only updates the modification time without changing the access time.
-R file: use the file time to update the file time.
-T change the time to the date specified by the parameter. For example, 07081556 indicates, January 1, July 8.
Example Touch updates existing files
$Ls-L firefox_wallpaper.png-RW-r --1Siu309597December20 15:03Firefox_wallpaper.png $TouchFirefox_wallpaper.png $Ls-L firefox_wallpaper.png-RW-r --1Siu309597January8 15:18Firefox_wallpaper.png
Touch does not have the option. It updates the file modification time and access time at the same time.
Touch creates a file
$TouchDemo. C $Ls-L total usage372-RW-r --1Siu0January8 15:21Demo. c
Touch-
First, check the original modification time and access time. The LS-lu command is used to view the access time.
$Ls-L total usage68-RW-r --1Siu66350December23 16:51Hs_err_pid2874.log $Ls-Total Lu usage68-RW-r --1Siu66350January8 15:17Hs_err_pid2874.log
Next is the updated modification time and access time.
$Touch-01081010Hs_err_pid2874.log $Ls-L total usage68-RW-r --1Siu66350December23 16:51Hs_err_pid2874.log $Ls-Total Lu usage68-RW-r --1Siu66350January8 10:10Hs_err_pid2874.log
We can see that the modification time has not changed, but the access time has changed.
Touch-m only updates the modification time
$ Ls - L total usage 68 -RW-r -- 1 Siu 66350 December 23 16 : 51 Hs_err_pid2874.log $ Touch - M hs_err_pid2874.log $ Ls - L total usage 68 -RW-r -- 1 Siu 66350 January 8 15 : 31 Hs_err_pid2874.log $ Ls - Total Lu usage 68 -RW-r -- 1 Siu 66350 January 8 10 :10 Hs_err_pid2874.log
The preceding example shows that the access time has not changed, but the modification time has changed.
Tips
1. You can use the default current time to update the file access time and modification time, or you can specify parameters to update files.
2. Generally, the most commonly used part of touch is creating new files.