In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to use the touch command to modify the file time in Linux. The content of the article is of high quality. Therefore, Xiaobian shares it with you as a reference. I hope that after reading this article, you will have a certain understanding of relevant knowledge.
Usage:
touch [Options]... Documents...
Change the access time and modification time of each file to the current time.
Files that do not exist will be created empty unless the-c or-h option is used.
If the file name is "-" special processing, change the access time of files related to standard output.
Parameters required for long options are also required for short options.
Parameters:
-a Change access time only
-c, --no-create does not create any files
-d, --date= string Replace the current time with the specified string representing the time
-f (ignored)
-h, --no-dereference affects the symbolic link itself, replacing the destination indicated by the symbolic link.
(This option is useful when the system supports changing the owner of symbolic links)
-m Change only modification time
-r, --reference= File replaces the current time with the time attribute of the specified file
-t STAMP replaces the current time with a time in the format [[CC]YY] MMDHhmm [.ss]
--time=WORD Use the time specified by WORD: access, atime, use are all equal to-a
option, while modify, mtime equals the effect of the-m option
--help Display this help message and exit
--version Display version information and exit
Note that the-d and-t options accept different time/date formats.
Example:
touch Update existing file time
The code is as follows:
$ ls -l Firefox_wallpaper.png
-rw-r--r-- 1 siu siu 309597 Dec 20 15:03 Firefox_wallpaper.png
$ touch Firefox_wallpaper.png
$ ls -l Firefox_wallpaper.png
-rw-r--r-- 1 siu siu 309597 Jan 8 15:18 Firefox_wallpaper.png
touch No option, updates both the modification time and access time of the file
touch Create file
The code is as follows:
$ touch demo.c
$ ls -l
Total consumption 372
-rw-r--r-- 1 siu siu 0 January 8 15:21 demo.c
touch -at Update access time using parameters
First look at the original modification time and access time, ls -lu is used to view access time
The code is as follows:
$ ls -l
Total consumption 68
-rw-r--r-- 1 siu siu 66350 Dec 23 16:51 hs_err_pid2874.log
$ ls -lu
Total consumption 68
-rw-r--r-- 1 siu siu 66350 Jan 8 15:17 hs_err_pid2874.log
Then there is the modification time and access time after the update
The code is as follows:
$ touch -at 01081010 hs_err_pid2874.log
$ ls -l
Total consumption 68
-rw-r--r-- 1 siu siu 66350 Dec 23 16:51 hs_err_pid2874.log
$ ls -lu
Total consumption 68
-rw-r--r-- 1 siu siu 66350 Jan 8 10:10 hs_err_pid2874.log
As you can see, the modification time has not changed, but the access time has changed.
touch -m Update modification time only
The code is as follows:
$ ls -l
Total consumption 68
-rw-r--r-- 1 siu siu 66350 Dec 23 16:51 hs_err_pid2874.log
$ touch -m hs_err_pid2874.log
$ ls -l
Total consumption 68
-rw-r--r-- 1 siu siu 66350 Jan 8 15:31 hs_err_pid2874.log
$ ls -lu
Total consumption 68
-rw-r--r-- 1 siu siu 66350 Jan 8 10:10 hs_err_pid2874.log
As you can see from the example above, the access time has not changed here, but the modification time has changed
Skills:
1. You can update file access and modification times with the default current time, or you can specify parameters to update
2. Usually, the most common use of touch is to create new files
About how to use touch command to modify file time in Linux to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.