View and modify the linux file time touch

  
        

1. Time of linux file
The file time under linux 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, no Includes modifications to file permissions and attributes. Use ls -l to view, 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)
The modification time of the file status status, such as 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)
File access time, this time is updated when the file content is retrieved. 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. Time to modify the file
If you need to modify the above three times, use the touch command to modify. 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 access time -c, --no -create do not create any files Modify the file for three times. If it does not exist, do not create -d, --date=STRING parse STRING and use it instead of current time. Specify the time instead of the current time -f (ignored) -m change only the Modification time 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 Specify 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 two days ago, ctime has not changed. 
$ 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.hatime and mtime both Changed, but ctime became the current time. With the cp command, -a keeps the original attributes. 
$ 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.h1mtime and Atime keeps the original file unchanged, but ctime becomes the current time address: http://blog.csdn.net/yonggang7/article/details/31008607
Copyright © Windows knowledge All Rights Reserved