One Linux command per day (9): Touch command

Source: Internet
Author: User
Tags touch command

Linux touch commands are not commonly used, and are generally used when using make, to modify file timestamps, or to create a new file that does not exist .

1. command format:

touch [Options] ... File...

2. Command parameters:

-A or--time=atime or--time=access or--time=use only change the access time.

-C or--no-create does not establish any documents.

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

-F This parameter ignores non-processing and is responsible only for compatibility issues with BSD version touch directives.

-M or--time=mtime or--time=modify only change the change time.

-R Sets 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 access time and change time.

4. Examples of use:

Instance one: Create a file that does not exist

Command:

Touch Log2012.log Log2013.log

Output:

[[email protected] test] # Touch log2012.log log2013.log

[[email protected] 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, the file is not created

[[email protected] test] # touch-c log2014.log

[[email protected] 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

Instance two: Update log.log time and log2012.log timestamp same

Command:

Touch-r Log.log Log2012.log

Output:

[[email protected] 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

[[email protected] 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 three: Setting the timestamp of a file

Command:

Touch-t 201211142234.50 Log.log

Output:

[[email protected] 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

[[email protected] 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 value specified as a new value for the corresponding time stamp of the specified file. The time specified here is a decimal number in the following form:

[[Cc]yy] mmddhhmm[. SS]

Here, CC is the first two digits of the number of years, that is, "century"; yy is the last two digits of the number of 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 for the number of months, DD for the day will be the number of years Ccyy limited to 1969--2068 within. MM is the number of months, DD is the number of days, HH is the number of hours (several), MM is the number of minutes, SS is the number of seconds. The set range of seconds here is 0--61, which can handle leap seconds. These numbers consist of a time in the time zone specified by the environment variable TZ. Due to system limitations, the time earlier than January 1, 1970 was wrong.

One Linux command per day (9): Touch command

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.