In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces in detail "how to use the touch command in the Linux system", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to use the touch command in the Linux system" can help you solve your doubts.
In the Linux system, the most basic function of the touch command is to create an empty file, and touch also changes the timestamp and modification time of the file.
Usage: touch [option]... Documents...
Update the access and modification times of each FILE to the current time.
A FILE argument that does not exist is created empty, unless-c or-h
Is supplied.
A FILE argument string of-is handled specially and causes touch to
Change the times of the file associated with standard output.
Required parameters apply to both length and length options.
-an only change the access time
-c,-no-create does not create any files
The-d,-date= string uses the specified string to represent the time instead of the current time
-f (ignore)
-h,-no-dereference affects the symbolic link itself, not the destination indicated by the symbolic link
(this option is useful when the system supports changing the owner of a symbolic link)
-m only change the modification time
-r.-reference=FILE use this file's times instead of current time.
-t STAMP use [[CC] YY] MMDDhhmm [.ss] instead of current time
-time=WORD change the specified time:
WORD is access, atime, or use: equivalent to-a
WORD is modify or mtime: equivalent to-m
-help displays this help and exits
-version displays version information and exits
Note that the-d and-t options accept different time / date formats.
1. Create an empty file using the touch command
The simplest and most basic use of the touch command is to create an empty file from the command line. If you are a terminal proficient, you can quickly create a new file on the command line with the following command:
$touch "filename"
Example:
$touch linuxidc
In the following example, I created an empty file named "linuxidc" with the touch command. Then I use the ls command to see if the file exists on the system, because the touch command does not prompt if the file has been created.
two。 Create more than one file at a time using the touch command
Although the cat command and standard redirection symbols are also ways to create files from the command line, the touch command has an advantage because you can create more than one file at a time. You can create multiple files with the touch command using the following syntax:
$touch linuxidc1 linuxidc2 linuxidc3... .
In the following example, I created three files at the same time with the touch command, and then used the ls command to see the existence of these files:
3. Force to avoid using the touch command to create a new file
Sometimes, if a new file does not exist, you need to avoid creating a new file. In this case, you can use the'- c 'option using the touch command, as follows:
$touch-c "filename"
In the following example, I use the touch command to avoid creating the above new file.
Touch-c linuxidc
When I use the ls command to list the file, the following output verifies that such a file exists on my system.
Linuxidc@linuxidc:~$ touch-c linux
Linuxidc@linuxidc:~$ ls linux
Ls: unable to access' linux': does not have that file or directory
4. Change the access and modification time of the file
Another use of the touch command is to change the access time and modification time of the file.
Let's give an example of how to do this. I created a file called "linuxmi" with the touch command and looked at its statistics through the stat command:
Then I entered the following touch command:
$touch linuxmi
This touch command changes the access and modification time to the time when the touch command is run again for "linuxmi". You can see the changed access and modification time in the figure above.
5. Change the access time or modification time
We can choose to change only one of them through the touch command instead of changing the access and modification time.
In the following example, I create a file called "linuxidc" and view the statistics through the stat command:
I can use the'- a 'option with the touch command on this file to change only the access time of this file:
$touch-a linuxidc
The output of the stat command now shows that the access time has been changed to the time I used the'- a 'option to run the touch command:
I can use the'- m 'option to change only the modification time of this file through the touch command on this file:
$touch-m linuxidc
The output of the stat command now shows that the modification time has been changed to the time the touch command was run with the'- m 'option:
6. How to copy access and modification times from one file to another
Let's assume that there is a file called linuxidcA:
Another file called linuxidcB:
If you want to change the access and modification time of linuxidcA to the access and modification time of linuxidcB, you can use the following touch command:
$touch linuxidcA-r sampleFileB
The output of the stat command in the figure above shows that linuxidcA now has the same access and modification values as samplefileB.
7. Create a new file using the specified timestamp
To create a new empty file with a specified timestamp instead of the actual time it was created, you can use the following syntax of the touch command:
$touch-t YYMMDDHHMM.SS "filename"
The following example shows how the stat command on my linuxidc shows that its access and modification time is based on the timestamp I provided when I created it with the touch command:
Create a new file with the specified timestamp
Touch-t 2006151230.30 linuxidc
8. Change the timestamp of the file to another time
You can change the timestamp of an existing file to a different time using the following syntax of the touch command:
$touch-c-t YYMMDDHHMM.SS "filename"
Touch-c-t 2008191130.30 linuxidc
In the following example, I changed the timestamp of an existing file with the touch command, and then verified the change with the stat command on the sample file:
Change the timestamp of the file to another time
After reading this, the article "how to use touch commands in Linux system" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.
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.