View and modify the linux File time touch

Source: Internet
Author: User

1. linux File time mainly has the following three types: 1.1 modification time (mtime) file modification time, that is, when the file content is modified, update this time, modification of file permissions and attributes is not included. Use ls-l for viewing. The default display time is mtime.

$ ls -l uconv.h-rw-rw-r--  1 work work 1808 Jul 23  2013 uconv.h
1.2 status time (ctime) indicates the modification time of the file status, such as the time when the file permissions and attributes are modified. Use ls -- time = ctime to view
$ ls -l --time=ctime uconv.h -rw-rw-r--  1 work work 1808 Jul 23  2013 uconv.h
1.3 access time (atime): the time when the file content is obtained. Use ls -- time = actime to view
$ ls -l --time=atime uconv.h-rw-rw-r--  1 work work 1808 Dec 12  2013 uconv.h
2. If you need to modify the Time of the file, use the touch command to modify it. Touch filename. If the file does not exist, create a new file.
$ Touch -- helpUsage: touch [OPTION]... FILE... update the access and modification times of each FILE to the current time. -a change only the access time: Modify the access time-c, -- no-create do not create any files to modify the file three times. If the file does not exist, do not create-d, -- date = STRING parse STRING and use it instead of current time specifies the time to replace the current time-f (ignored)-m change only the modification time to modify mtime-r, -- reference = FILE use this file's times instead of current time-t STAMP use [[CC] YY] MMDDhhmm [. ss] instead of current time specifies the modification time
For example:
$ touch -d "2 days ago" uconv.h$ ll uconv.h ; ll --time=atime uconv.h ; ll --time=ctime uconv.h ;-rw-rw-r--  1 work work 1808 Jun 13 18:17 uconv.h-rw-rw-r--  1 work work 1808 Jun 13 18:17 uconv.h-rw-rw-r--  1 work work 1808 Jun 15 18:17 uconv.h
Change mtime and atime to ctime two days ago.
$ touch -t 201406142020 uconv.h   $ ll uconv.h ; ll --time=atime uconv.h ; ll --time=ctime uconv.h ;-rw-rw-r--  1 work work 1808 Jun 14 20:20 uconv.h-rw-rw-r--  1 work work 1808 Jun 14 20:20 uconv.h-rw-rw-r--  1 work work 1808 Jun 15 18:23 uconv.h
Atime and mtime have both changed, but ctime has changed to the current time.
Use the cp command to maintain the original attribute of-.
$ cp -a uconv.h uconv.h1$ ll uconv.h1 ; ll --time=atime uconv.h1 ; ll --time=ctime uconv.h1 ;-rw-rw-r--  1 work work 1808 Jun 14 20:20 uconv.h1-rw-rw-r--  1 work work 1808 Jun 15 18:25 uconv.h1-rw-rw-r--  1 work work 1808 Jun 15 18:27 uconv.h1
Both mtime and atime keep the original file unchanged, but ctime changes to the current time.

Address: http://blog.csdn.net/yonggang7/article/details/31008607

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.