Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the Linux command touch

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains the "Linux command touch use", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's train of thought slowly in depth, together to study and learn "Linux command touch use" bar!

The touch command of linux is not commonly used, and it may be used to modify the file timestamp or to create a new file that does not exist when using make.

1. Command format:

Touch [options]... Documents...

two。 Command parameters:

-an or-time=atime or-time=access or-time=use only changes the access time.

-c or-no-create does not establish any documentation.

-d uses the specified date time instead of the current time.

-f this parameter is ignored and not processed, and is only responsible for resolving the compatibility issue of the BSD version of the touch directive.

-m or-time=mtime or-time=modify only changes the time of change.

-r set the date and time of the specified document or directory to the same date and time as the reference document or directory.

-t uses the specified date time instead of the current time.

3. Command function:

The touch command parameter changes the date time of the document or directory, including the access time and the change time.

4. Examples of use:

Example 1: create a file that does not exist

Command:

Touch log2012.log log2013.log

Output:

[root@localhost test] # touch log2012.log log2013.log

[root@localhost test] # ll

-rw-r--r-- 1 root root 0 10-28 16:01 log2012.log

-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

If log2014.log does not exist, no file is created

[root@localhost test] # touch-c log2014.log

[root@localhost test] # ll

-rw-r--r-- 1 root root 0 10-28 16:01 log2012.log

-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

Example 2: update the log.log with the same time stamp as the log2012.log timestamp

Command:

Touch-r log.log log2012.log

Output:

[root@localhost test] # ll

-rw-r--r-- 1 root root 0 10-28 16:01 log2012.log

-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

-rw-r--r-- 1 root root 0 10-28 14:48 log.log

[root@localhost test] # touch-r log.log log2012.log

[root@localhost test] # ll

-rw-r--r-- 1 root root 0 10-28 14:48 log2012.log

-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

-rw-r--r-- 1 root root 0 10-28 14:48 log.log

Example 3: set the timestamp of the file

Command:

Touch-t 201211142234.50 log.log

Output:

[root@localhost test] # ll

-rw-r--r-- 1 root root 0 10-28 14:48 log2012.log

-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

-rw-r--r-- 1 root root 0 10-28 14:48 log.log

[root@localhost test] # touch-t 201211142234.50 log.log

[root@localhost test] # ll

-rw-r--r-- 1 root root 0 10-28 14:48 log2012.log

-rw-r--r-- 1 root root 0 10-28 16:01 log2013.log

-rw-r--r-- 1 root root 0 2012-11-14 log.log

Description:

-t time uses the specified time value time as the new value for the corresponding timestamp of the specified file. The time here is specified as a decimal number in the following form:

[[CC] YY] MMDDhhmm [.SS]

Here, CC is the first two of the years, that is, the century; YY is the last two of the years, that is, the number of years in a century. If the value of CC is not given, touch will limit the number of years CCYY to 1969-2068. MM is the number of months, DD is the day, the number of years CCYY is 1969-2068. MM is the number of months, DD is the number of days, hh is the number of hours (points), mm is the number of minutes, SS is the number of seconds. The set range of seconds here is 0-61, so you can handle leap seconds. The time composed of these numbers is one of the time zones specified by the environment variable TZ. Due to system limitations, a time earlier than January 1, 1970 is wrong.

Thank you for your reading, the above is the content of "the use of Linux command touch", after the study of this article, I believe you have a deeper understanding of the use of Linux command touch, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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: 249

*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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report