In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to use the touch command under Linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Basic usage of touch command
When you mention the touch command, you must think of its two uses:
Change the timestamp
Create a new file
People have long been tired of using these two usages in their work, so I won't repeat them any more.
Prevent the creation of files
If a file name is followed directly after the touch, a file with the corresponding name will be created if the file does not exist. So what if we just want to change the timestamp of the file, and what if we don't create the file when the file doesn't exist? The-c option needs to be added here.
[alvin@VM_0_16_centos test] $touch-c alvin [alvin@VM_0_16_centos test] $ll alvin ls: cannot access alvin: No such file or directory
Only change the file access time
We know that when the touch command is executed without any option, the file access time and modification time are changed to the current system time at the same time. As follows:
[alvin@VM_0_16_centos test] $stat file File: 'file' Size: 10 Blocks: 8 IO Block: 4096 regular file Device: fd01h/64769d Inode: 371115 Links: 1 Access: (0664Accord) Uid: (1000 / alvin) Gid: (1000 / alvin) Access: 2019-02-20 14 rips 2021.21 154819675 + 0800 Modify: 2019-02-20 14:20 : 21.154819675 + 0800 Change: 2019-02-20 14 touch file 20 touch file 21.191819649 + 0800 Birth:-[alvin@VM_0_16_centos test] $touch file # use the touch command [alvin@VM_0_16_centos test] $stat file File: 'file' Size: 10 Blocks: 8 IO Block: 4096 regular file Device: fd01h/64769d Inode: 371115 Links: 1 Access: (0664) /-rw-rw-r--) Uid: (1000 / alvin) Gid: (1000 / alvin) Access: 2019-02-20 21V 51Visa 24.848774158 + 0800 # the access time / modification time of the file has been changed to the current system time Modify: 2019-02-20 21V 5124.848774158 + 0800 Change: 2019-02-20 21V 51v 24.848774158 + 0800 Birth:-
Using the stat command here, you can view more detailed information about the file.
If we just want to change the access time of the file, we just need to add the-an option, which is the abbreviation of the word access.
[alvin@VM_0_16_centos test] $touch-a file [alvin@VM_0_16_centos test] $stat file File: 'file' Size: 10 Blocks: 8 IO Block: 4096 regular file Device: fd01h/64769d Inode: 371115 Links: 1 Access: (0664MB) Uid: (1000 / alvin) Gid: (1000 / alvin) Access: 2019-02-20 21 : 56 Modify 40.858021859 + 0800 # only the timestamp of the access time has been changed. Modify: 2019-02-20 21V 51RV 24.848774158 + 0800 # the modification time remains the same Change: 2019-02-20 21VZ 5640.858021859 + 0800 Birth:-
Only change the modification time
If we just want to change the modification time of the file, we just need to add the-m option, which is the abbreviation of the word modify.
[alvin@VM_0_16_centos test] $touch-m file [alvin@VM_0_16_centos test] $stat file File: 'file' Size: 10 Blocks: 8 IO Block: 4096 regular file Device: fd01h/64769d Inode: 371115 Links: 1 Access: (0664MB) Uid: (1000 / alvin) Gid: (1000 / alvin) Access: 2019-02-20 21 : 56 Modify 40.858021859 + 0800 Birth: 2019-02-20 22 Birth 07 Birth 39.138701655 + 0800 Birth:-
Change to a custom timestamp
Whether there is no option or the-an or-m option, the corresponding time of the file is changed to the current system timestamp. What if we want to change to a custom timestamp? What are we going to do with it? Otherwise, how can it be time travel?
We have two ways to change to a custom timestamp.
1. Add the-t option
For example, we change the timestamp of the file to a future time:
[alvin@VM_0_16_centos test] $touch-t 202001012020.20 file [alvin@VM_0_16_centos test] $stat file File: 'file' Size: 10 Blocks: 8 IO Block: 4096 regular file Device: fd01h/64769d Inode: 371115 Links: 1 Access: (0664mow Links: 1 Access) Uid: (1000 / alvin) Gid: (1000 / alvin) Access: 2020-01 -01 20 Modify 20 Birth 20.000000000 + 0800 Birth: 2020-01-01 20 Birth 20 Birth:-01-01-01 20 Birth:-
Here, the format of the timestamp followed by-t is:
[[CC] YY] MMDDhhmm [.SS]
Specifically, it goes like this:
CC-first two digits of the year YY-last two digits of the year MM-month [01-12] DD-date [01-31] hh-hour [00-23] mm-minutes [00-59] SS-seconds [00-61]
two。 Add the-d option
Let's use a new method to change the timestamp of the document to a past time (the opening ceremony of the 2008 Olympic Games):
[alvin@VM_0_16_centos test] $touch-d'08 alvin@VM_0_16_centos test Augusttel 2008 file [alvin@VM_0_16_centos test] $stat file File: 'file' Size: 10 Blocks: 8 IO Block: 4096 regular file Device: fd01h/64769d Inode: 371115 Links: 1 Access: (0664 Access) Uid: (1000 / alvin) Gid: (1000 / alvin) Access : 2008-08-0800: 00 Birth 00.000000000 + 0800 Modify: 2008-08-0800: 00 Birth 00.000000000 + 0800 Birth:-
Here, the format of time is: day-month-year. However, the time here can be quite flexible, for example, it also supports yesterday, 1 year ago, and so on:
[alvin@VM_0_16_centos test] $touch-d'yesterday 08 'file [alvin@VM_0_16_centos test] $stat file File:' file' Size: 10 Blocks: 8 IO Block: 4096 regular file Device: fd01h/64769d Inode: 371115 Links: 1 Access: (0664 Links RW Muhammad -) Uid: (1000 / alvin) Gid: (1000 / alvin) Access: 2008-08-07 00 Access 00.000000000 + 0800 Modify: 2008-08-07 00 Change 00.000000000 + 0800 Birth:-
In addition to changing the time, it can also change the time zone.
To change the time zone, just follow the corresponding time zone after-d.
Thank you for reading! This is the end of the article on "how to use touch commands under Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.