Linux file directory time update touch command usage

Source: Internet
Author: User
Tags time and date touch touch command


Name: Touch
Use Rights: All users
How to use:
Touch [-acfm]
[R Reference-file] [--file=reference-file]
[-t MMDDHHMM[[CC]YY][.SS]]
[-D Time] [--date=time] [--time={atime,access,use,mtime,modify}]
[--no-create] [--help] [--version]
File1 [File2 ...]
Description
The touch command changes the time record of the file. Ls-l can display the time record of the file.
Parameters:
A change the read time record of the file.
M changes the file's modification time record.
c If the destination file does not exist, no new files will be created. The same as the--no-create effect.
F is not used and is reserved for compatibility with other UNIX systems.
R use the reference file's time record as--file.
D Set the time and date, you can use a variety of different formats.
T sets the file's time record in the same format as the date instruction.
--no-create will not create new files.
--HELP lists the instruction formats.
--version lists version messages.
Use Example:
Instance one: Creating 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 0 10-28 16:01 log2012.log
-rw-r--r--1 root 0 10-28 16:01 log2013.log
If Log2014.log does not exist, the file is not created
[Root@localhost test]# touch-c Log2014.log
[Root@localhost test]# LL
-rw-r--r--1 root 0 10-28 16:01 log2012.log
-rw-r--r--1 root 0 10-28 16:01 log2013.log
Instance two: Update Log.log time and Log2012.log time stamp the same
Command:
Touch-r Log.log Log2012.log
Output:
[Root@localhost test]# LL
-rw-r--r--1 root 0 10-28 16:01 log2012.log
-rw-r--r--1 root 0 10-28 16:01 log2013.log
-rw-r--r--1 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 0 10-28 14:48 log2012.log
-rw-r--r--1 root 0 10-28 16:01 log2013.log
-rw-r--r--1 root 0 10-28 14:48 log.log

Example three: Set the timestamp of a file

Command:
Touch-t 201211142234.50 Log.log
Output:
[Root@localhost test]# LL
-rw-r--r--1 root 0 10-28 14:48 log2012.log
-rw-r--r--1 root 0 10-28 16:01 log2013.log
-rw-r--r--1 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 0 10-28 14:48 log2012.log
-rw-r--r--1 root 0 10-28 16:01 log2013.log
-rw-r--r--1 root 0 2012-11-14 log.log

Description

The

-t  time uses the value of a specified timestamp as the new value for the appropriate timestamp for the specified file. The time here is defined as a decimal number in the form:     
  [cc]yy]mmddhhmm[. ss]    
  Here, CC is the first two digits of the year, the number of centuries, and yy is the last two digits of the year, the number of years in a century. If the value of CC is not given, then touch   will limit the number of years Ccyy to 1969--2068. MM is the number of months, DD for days will be the number of years Ccyy limited within the 1969--2068. MM is the number of months, DD is the number of days, HH for hours (several), MM for minutes, SS for seconds. The set of seconds here is 0--61 so that you can handle leap seconds. These numbers consist of a time in the specified time zone of the environment variable TZ. Due to the limitations of the system, the time earlier than January 1, 1970 is wrong.

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.