Linux timestamp atime ctime mtime differences and related commands

Source: Internet
Author: User
Tags touch command

Let's start with a brief look at the concept of Linux timestamp atime CTime mtime

Atime:access time when the file (read or execute) or directory was last accessed

Mtime:modofy time when the file (content) or directory (content) was last modified

Ctime:change time when the file (attribute) or directory (attribute) was last changed


The difference between atime CTime mtime

Atime

Access Time (Atime): Refers to the timing of the use of files, the so-called access, common operations are: Use the editor to view the contents of the file, using the Cat command to display the contents of the file, using the CP command to copy the file (that is, the source file) to other files, or on this file using grep sed More less tail head and other commands, usually read without modifying the file's operation, equalization changes to the file's access time.

Mtime

Modify Time (Mtime): Refers to the change in the content of the file, as long as the contents of the file changes (such as the use of the switch to the output or the way to attach) or disk operation, it will change the modify time of the file, usually when we use Ls–l to view the file, the display is modify Time.

CTime

Change Time (CTime): Refers to the timing of file attributes or file location changes, such as the use of the CHMOD,CHOWN,MV instruction set to use LN to do a file with a obstinately connected, the file changes will be changed.


Two ways to view timestamps:

1. Stat filename

2. Atime:ls-lu filename

mtime:ls-l filename

CTIME:LS-LC filename


Here is a shell command to intercept mtime:

Stat FileName | Grep-i Modify | Awk-f. ' {print $} ' | awk ' {print $2$3} ' | awk-f-' {print $1$2$3} ' | Awk-f: ' {print $1$2$3} '


The function of the Touch command is to change the timestamp of the file, and the syntax of the touch commands is as follows:

touch [options] ... filename ...

Options and Parameters:

-A: revision atime only;

-C: Only modify the time of the file, if the file does not exist, do not create a new file;

-D: You can follow the date you want to revise instead of the current date, or you can use the--date= "date or time"

-M: Modify Mtime only;

-T: The time after which the revision can be received instead of the current time, in the format [YYMMDDHHMM]

-R: Set the date and time of the specified document or directory to the same date and time as the reference document or directory

...


Note:

(1) If you modify the file (using the editor to save or use >> to turn the operation), the modify time and change times will be updated synchronously to write, but access does not change.

(2) If touch file is executed, all 3 time changes

(3) The use of ln-s to make a soft link to the file will change the time the file is taken Atime

(4) Use Ls-la to view generic files, do not change these three times, but if the file is a symbolic link to the file, it will change the time taken for access

(5) Ls-l default display time is the mtime of the file


Linux timestamp atime ctime mtime differences and related commands

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.