One day learning Linux atime, mtime, ctime

Source: Internet
Author: User
Tags touch command
In fact, I don't want to talk about this content separately, but some friends may not quite understand these three times, so I will study it with you. In Linux, there are three recording methods for file Time: mtime (modificationtime...

 

In fact, I don't want to talk about this content separately, but some friends may not quite understand these three times, so I will study it with you.

 

In Linux, there are three recording methods for file time.

Mtime (modification time): the time when the file content changes when the file is written. The time we see with ls-l is mtime.

Ctime (status time): the time when Inode content changes when a file is written, the owner is changed, permissions, or links are set. Equivalent to the time seen by ls-l-time = ctime

Atime (access time): the time when the file is read or executed. That is, the time displayed by using ls-l-time = atime

 

The following three examples can be used for comparison.

Ls-l install. log; ll-time = ctime install. log; ll-time = atime install. log

The specific content is not described here. you can understand it carefully and I don't think it is difficult.

It is precisely because of these time relationships that there may be a gap between the time of a file and the current system time. Because the time around the world is different.

The above three time definitions are also very simple. The key is to understand, and the method to deepen understanding is to practice on your own. OK. next we will introduce you to the touch command, which is used to "change the file or directory time command ".

 

Change file or directory time command touch

Parameter description

-A: modify atime

-M: modify mtime

-C: only modify the time of the file (modified together with three times). If the file does not exist, no new file is created.

-D: the end can be followed by the date you want to modify, instead of the current date, you can also use-date = "date or time"

-T: you can modify the time later than the current time in the format of [YYMMDDhhmm].

 

Let's look at an example.

[Root @ yufei ~] # Ls-l install. log; ll-time = ctime install. log; ll-time = atime install. log

-Rwxr-r-. 1 root 31537 Jan 20 05:09 install. log

-Rwxr-r-. 1 root 31537 Feb 9 19: 25 install. log

-Rwxr-r-. 1 root 31537 Feb 11 16: 28 install. log

[Root @ yufei ~] # Touch-c install. log

[Root @ yufei ~] # Ls-l install. log; ll-time = ctime install. log; ll-time = atime install. log

-Rwxr-r-. 1 root 31537 Feb 11 20:38 install. log

-Rwxr-r-. 1 root 31537 Feb 11 20:38 install. log

-Rwxr-r-. 1 root 31537 Feb 11 20:38 install. log

In the preset state, if there is a file after touch, the three times (atime/ctime/mtime) of the file will be updated to the current time. If this file does not exist, a new empty file is automatically created. Unlike the-c parameter,-c does not create a file! You can touch a file and check it out.

 

Let's look at an example.

[Root @ yufei ~] # Cp-a/etc/profile ./

[Root @ yufei ~] # Ls-l profile; ls-l-time = atime profile; ls-l-time = ctime profile

-Rw-r-. 1 root 1459 Jun 30 2010 profile

-Rw-r-. 1 root 1459 Feb 11 10:51 profile

-Rw-r-. 1 root 1459 Feb 11 20:46 profile

The first line is the mtime of the file, that is, the time when the file was created or edited.

The second behavior is the atime of this file. this time is the last access time of this file.

The third behavior is the ctime of this file. because the file was just copied, the I node of this file must be different from the original file.

[Root @ yufei ~] # Ls-li/etc/profile; ls-li profile

651556-rw-r-. 1 root 1459 Jun 30 2010/etc/profile

522034-rw-r-. 1 root 1459 Jun 30 2010 profile

I hope you can understand these three times through the above explanation.

From the above example, we can see that even if we copy all the attributes when copying a file, there is no way to copy the ctime attribute. Ctime records the time when the latest status (status) of the file is changed.

 

If you want to change the time, we can use the following method to implement

For example, change the date and time of the file to "2010/11/22 8:08 ″

[Root @ yufei ~] # Touch-t 1011220808 profile

[Root @ yufei ~] # Ls-l profile; ls-l-time = atime profile; ls-l-time = ctime profile

-Rw-r-. 1 root 1459 Nov 22 08:08 profile

-Rw-r-. 1 root 1459 Nov 22 08:08 profile

-Rw-r-. 1 root 1459 Feb 11 21:02 profile

We can see that both atime and mtime have changed, but ctime records the current time of the system.

 

There are only two common functions of touth.

1. create an empty file

2. modification time (mtime atime). However, this function is not used much.

 

I hope that you can have a deep understanding of these three times.

From Yu Fei's blog

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.