Touch commands and file timestamps for Linux files

Source: Internet
Author: User
Tags touch command

First , take a look at the file's properties on time before naming touch. the following files are viewed through the stat command:

[Email protected] test]# stat F1 File: ' F1 ' size:34 blocks:8 IO block:4096 regular Filedevice: fd00h/64768d inode:72757 links:1access: (0640/-rw-r-----) Uid: (0/root) Gid: (0/root) Access:2 015-10-09 01:26:41.658883440 +0800modify:2015-10-08 04:05:15.000000000 +0800change:2015-10-08 20:20:32.811903158 + 0800

View the above information see file three properties

AcessTime: That is, file access times, or " last Read time ", such as the use of touch,cat, More commands will modify this value, But using ls,stat viewing does not change. Note: If you are using a virtual machine test, you will find that the cat, More commands are not updated in real time, and you can use physical machine testing.

ModifyTime: Modified, this refers to the last time the file content was modified. The LS command displays this time by default.

Change Time: This refers to the last modification time of the file attributes, such as modifying permissions, names, etc., and must be distinguished from Modify .

second,Touch command: Used to modify the file timestamp, or create a new file.

1, option parameter

-A:--time=atime Acess time;

-M:--time=mtime Modify time;

-C:--no-create does not create any documents. By default, files are created when the file does not exist, and-C can not be created.

-R: The same date and time as the file settings and reference files.

-T: Use the specified time date instead of using the system time directly.

Third, examples

1, first touch a file that already exists

[[email protected] test]# stat f1 file:  ' F1 '  Size: 34               Blocks:8           io block: 4096   regular filedevice: fd00h/ 64768d    inode: 71660       links: 1access:   (0640/-rw-r-----)   Uid:  (   0/    root)     Gid:  (   0/    root) access: 2015-10-09  17:28:43.853828458 +0800modify: 2015-10-08 04:05:15.000000000 +0800change: 2015-10-09  03:16:57.117877086 +0800[[email protected] test]# touch f1[[email  protected] test]# stat f1  #可以看到所有文件时间都更新为当前系统时间.  File:  ' F1 '  size: 34       &nbsP;      blocks:8          io  Block: 4096   regular fileDevice: fd00h/64768d     inode: 71660       links: 1access:  (0640/-rw-r-----)    Uid:  (   0/    root)    Gid:  (    0/    root) access: 2015-10-09 18:17:22.936820504 +0800modify:  2015-10-09 18:17:22.936820504 +0800change: 2015-10-09 18:17:22.936820504 +0800[[email  protected] test]# datefri oct 9 18:17:29 cst 2015

2. Create a file with the Touch command

[[email protected] test]# touch-c f3 #-c do not create file [[email protected] test]# LSF1 f2 test[[email protected] test]# touch F3 #创 Build file F3[[email protected] test]# LSF1 F2 f3 test[[email protected] test]# file F3 #查看f3文件类型, shown as empty F3:empty

3, modify the file time for the specified time

View touch–t parameters by man :

-T STAMP use [[CC]YY]MMDDHHMM[.SS] instead of currenttime

[[email protected] test]# touch -t201510081010.10  f3[[email protected] test]# stat f3  #修改时间为指定时间日期  File:  ' F3 '  size :  4               blocks:8           io block: 4096   regular  fileDevice: fd00h/64768d    Inode: 66037        Links: 1Access:  (0644/-rw-r--r--)   Uid:  (   0/     root)    Gid:  (   0/    root) access:  2015-10-08 10:10:10.000000000 +0800modify: 2015-10-08 10:10:10.000000000 +0800change:  2015-10-09 18:34:22.535825523 +0800# Note that CTime is the current time because the file properties are changed. 


4, aligns the file time with the specified reference file time.

[Email protected] test]# touch-r f3 F1 #将f1时间改为与f3相同 [[email protected] test]# stat F1 File: ' F1 ' size:34 B   Locks:8 IO block:4096 Regular filedevice:fd00h/64768d inode:71660 links:1access: (0640/-rw-r-----) Uid: (0/root) Gid: (0/root) access:2015-10-08 10:10:10.000000000 +0800modify:2015-10-08 10:10:10.000000 +0800change:2015-10-09 18:42:47.175819324 +0800# same CTime still current time.


Summary:the Touch command is still relatively simple, mainly to understand the three time attributes about the file.


This article is from the "Ding classmate 1990" blog, please be sure to keep this source http://dingtongxue1990.blog.51cto.com/4959501/1704051

Touch commands and file timestamps for Linux files

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.