The Linux Touch command modifies the timestamp of the file

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

Function: Modify the time that the file already exists, Access time (modification time). Create a new blank file for files that do not exist.

Syntax: Touch [Options] File
Short Options Long Options meaning
-A --time=atime
or--time=access
or--time= use
Change access time only
-M --time=mtime
or--time=modify
Change time only
- D time --date= String Set time and date, you can use a variety of different formats
-T STAMP Sets the timestamp. Stamp is a decimal number: [[cc]yy]mmddhhmm[]. SS]
CC is the first two digits in 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 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
-R FILE Set the date and time of the specified document or directory to the same date and time as the reference document or directory
-C --no-create Do not create any documents
Multiple Time properties for Linux:
Access time is the date the document was last read. So reading a document updates its access time, but its modify time and change time are unchanged. Cat, more, less, grep, sed, tail, head These commands modify the file's access time.
Change time is the document's index node (inode) that has changed (such as location, user attributes, group properties, and so on). chmod, CHOWN,CREATE,MV, and so on will change the Linux file to the current time of the system.
Modify time is the content of the text itself has changed. [The Modify time of the document is also called a timestamp (timestamp).] The LS command sees modify time. After editing a file with VI and other tools, modify time will be modified.

Create new file [[email protected] ~]# ls-l new.txt ls:new.txt: No file or directory [[email protected] ~]#touch new.txt[[email protected] ~]# ls-l new.txt-rw-r--r--1 root root 0 10-11 22:40 new.txt [[email protected] ~]# change file time to current time [[E] Mail protected] ~]# ls-l new.txt-rw-r--r--1 root root 0 10-11 22:40 new.txt [[email protected] ~]#touch new.txt[[email protected] ~]# ls-l new.txt-rw-r--r--1 root root 0 10-11 22:41 new.txt change file time to specified time [[email protected] ~]# dat E October 11, 2010 Monday 22:42:54 CST [[email protected] ~]#touch -t 10112200 new.txt<=== format mmddhhmm[Email protected] ~]# ls-l new.txt-rw-r--r--1 root root 0 10-11 22:00 new.txt [[email protected] ~]#touch -t 200910112200 new.txt<=== format yyyymmddhhmm[Email protected] ~]# ls-l new.txt-rw-r--r--1 root root 0 2009-10-11 new.txt [[email protected] ~]# [[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 [email protected] test]#touch -t 201211142234.50 log.log201211142234.50 time Stamp[[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 l og2013.log-rw-r--r--1 root root 0 2012-11-14 log.logchange the file's time record to May 6 18:3, A.D. 2000. Time can use AM, PM or 24 hours format, date can use other formats such as 6 May 2000. Touch-d "6:03pm"fileTouch-d "05/06/2000"filetouch-d "6:03pm 05/06/2000"fileChange the file time to be the same as other files [[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 [[email protected] 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 l og2013.log-rw-r--r--1 root root 0 10-28 14:48 log.log

The Linux Touch command modifies the timestamp of the file

Related Article

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.