In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 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 Linux touch command", the content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to use the Linux touch command" can help you solve your doubts.
Syntax touch [- acfm] [- d] [- r] [- t] [--help] [--version] [file or directory...] Parameter description: a changes the reading time record of the file.
M change the modification time record of the file.
C if the destination file does not exist, no new file will be created. It has the same effect as-no-create.
F is not used and is reserved for compatibility with other unix systems.
R uses the time record of the reference file, which is the same as that of-file.
D set the time and date, you can use a variety of different formats.
T sets the time record of the file in the same format as the date instruction.
-no-create will not create a new file.
-help lists the instruction format.
-version lists version messages.
Touch command application example: 1 create an empty file using touch to create an empty file on a Linux system using the touch command, type touch, and then enter a file name. As follows:
[root@linuxtechi ~] # touch devops.txt [root@linuxtechi ~] # ls-l devops.txt-rw-r--r--. 1 root root 0 Mar 29 22:39 devops.txt example: 2 creating batch empty files using touch may occur and we have to create a large number of empty files for some tests, which can be easily achieved using the touch command:
[root@linuxtechi ~] # touch sysadm- {1.. 20} .txt in the above example, we created 20 empty files called sysadm-1.txt to sysadm-20.txt, and you can change the name and number as needed.
Example: 3 change / update the access time of files and directories suppose we want to change the access time of the file named devops.txt, use the-an option in the touch command, and then enter the file name. As follows:
[root@linuxtechi ~] # touch-a devops.txt now uses the stat command to verify that the access time of the file has been updated:
[root@linuxtechi ~] # stat devops.txt File: 'devops.txt' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd00h/64768d Inode: 67324178 Links: 1 Access: 2018-03-29 23 Birth 03RV 10.902000000-0400 Modify: 2018-03-29 2222 Birth: 39RV 29.365000000-0400 Birth:-change the access time of the directory:
Suppose we have a nfsshare folder under the / mnt directory, let's change the access time of this folder with the following command:
[root@linuxtechi ~] # touch-m / mnt/nfsshare/ [root@linuxtechi ~] # stat / mnt/nfsshare/ File:'/ mnt/nfsshare/' Size: 6 Blocks: 0 IO Block: 4096 directory Device: fd00h/64768d Inode: 2258 Links: 2 Access: (0755/drwxr-xr-x) Uid: (0 / root) Gid: (0 / root) Context: unconfined _ u:object_r:mnt_t:s0 Access: 2018-03-29 23 Change 34 Birth 38.095000000-0400 Modify: 2018-03-03 10 Change 42mer 45.194000000-0500 Birth:-example: 4 change the access time without creating a new file in some cases If the file exists, we want to change the access time of the file and avoid creating the file. You can use the-c option in the touch command, and if the file exists, we can change the access time of the file, or we won't create it if it doesn't exist.
[root@linuxtechi ~] # touch-c sysadm-20.txt [root@linuxtechi ~] # touch-c winadm-20.txt [root@linuxtechi ~] # ls-l winadm-20.txt ls: cannot access winadm-20.txt: No such file or directory example: 5 change the modification time of files and directories using the-m option in the touch command, we can change the modification time of files and directories.
Let's change the change time to the devops.txt file:
[root@linuxtechi ~] # touch-m devops.txt now uses the stat command to verify that the modification time has changed:
[root@linuxtechi ~] # stat devops.txt File: 'devops.txt' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd00h/64768d Inode: 67324178 Links: 1 Access: 2018-03-29 23 Birth 03RV 10.902000000-0400 Modify: 2018-03-29 23V 59RV 49.106000000-0400 Change: 2018-03-29 23V 59mer 49.106000000-0400 Birth:-same We can change the modification time of a directory:
[root@linuxtechi ~] # touch-m / mnt/nfsshare/ uses stat cross-validation access and modification time:
[root@linuxtechi ~] # stat devops.txt File: 'devops.txt' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd00h/64768d Inode: 67324178 Links: 1 Access: 2018-03-30 00 Birth 06V 20.145000000-0400 Modify: 2018-03-30 00 Birth 06V 20.145000000-0400 Birth:-example: 7 set the access and modification time to a specific date and time whenever we use the touch command to change the access and modification time for files and directories It sets the current time to the access and modification time of the file or directory.
Suppose we want to set a specific date and time to the access and modification time of the file, which can be done using the-c and-t options in the touch command.
The date and time can be specified in the following format:
{CCYY} MMDDhhmm.ss where:
CC-the first two digits of the year
YY-the last two digits of the year
MM-month (01-12)
DD-Day (01-31)
Hh-hour (00-23)
Mm-minutes (00-59)
Let's set the access and modification time of the devops.txt file to a future time (18:20, October 19, 2025).
[root@linuxtechi ~] # touch-c-t 202510191820 devops.txt use the stat command to check the update access and modification time:
Stat-command-output-linux
Set the access and modification time based on the date string, use the-d option in the touch command, and then specify the date string, followed by the file name. As follows:
[root@linuxtechi ~] # touch-c-d "2010-02-07 20 sysadm-29.txt 15bank 12.000000000 + 0530" sysadm-29.txt uses the stat command to verify the status of the file:
[root@linuxtechi ~] # stat sysadm-20.txt File: 'sysadm-20.txt' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd00h/64768d Inode: 67324189 Links: 1 Access: (0644 Maxima, RWMurray, Rafael -) Uid: (0 / root) Gid: (0 / root) Context: unconfined_u:object_r:admin_home_t : S0 Access: 2010-02-07 20 Change 15 Birth 12.000000000 + 0530 Modify: 2010-02-07 20 Change 15 Change 12.000000000 + 0530 Birth:-Note: in the above command If we do not specify-c, then the touch command will create a new file and set the timestamp to the one given in the command if the file does not exist on the system.
Example: 8 use reference files to set timestamps (- r) in the touch command, we can use reference files to set timestamps for files or directories. Suppose I want to set the same timestamp on the devops.txt file as the file sysadm-20.txt file, which can be easily achieved by using the-r option in the touch command.
Syntax:
# touch-r {reference file} Real file [root@linuxtechi ~] # touch-r sysadm-20.txt devops.txt example: 9 change the access and modification time on a symbolic link file by default, whenever we try to change the timestamp of a symbolic link file using the touch command, it only changes the timestamp of the original file. If you want to change the timestamp of the symbolic link file, you can use the-h option in the touch command to do so.
Syntax:
[root@linuxtechi opt] # ls-l / root/linuxgeeks.txt lrwxrwxrwx. 1 root root 15 Mar 3010: 56 / root/linuxgeeks.txt-> linuxadmins.txt [root@linuxtechi] # touch-t 203010191820-h linuxgeeks.txt [root@linuxtechi] # ls-l linuxgeeks.txt lrwxrwxrwx. 1 root root 15 Oct 19 2030 linuxgeeks.txt-> linuxadmins.txt here, this article "how to use Linux touch commands" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it before you can 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.