Home  >  Article  >  System Tutorial  >  Mastering Linux File Time: From Getting Started to Practical Combat

Mastering Linux File Time: From Getting Started to Practical Combat

WBOY
WBOYforward
2024-02-10 15:24:07605browse

File time is an important concept in Linux systems. It not only records the creation, modification and access time of files, but also helps us with file management, backup and recovery. For Linux system administrators, understanding file time-related knowledge is essential.

Three times of the file

I believe everyone is already familiar with the windows operating system. When we create a file under the windows system, the system will also establish relevant parameters for the file to describe the file, as shown in the figure:

Mastering Linux File Time: From Getting Started to Practical Combat

These parameters include the file size, file type, location, and the creation, modification, and access times of the three files. So let's see if there are similar parameters under the Linux system?
Under Linux, we can use the stat file name to view the relevant parameters of the file. The specific parameters are explained as follows:

Mastering Linux File Time: From Getting Started to Practical Combat

In the file system in Linux, we found that in addition to the file size, file name, file time, etc., there is also more information about the Inode number and block. This is mainly related to the composition of the Linux file system. A file under Linux has an Inode number, and an Inode number corresponds to at least one block. Bolck is a structure for accessing file content. The number of file blocks is related to the size of the file, and under the Linux system, the size of the block is stable. Today we mainly introduce the three times under the Linux system. They are
Access Time, Modify Time, Change Time.

atime

atime is the abbreviation of Access Time. It is called access time in the Linux file system. When the content of the file is accessed, this time will be updated. For example, we use cat, more, less and other commands to view the file. content, the access time of the file will be updated, as shown below:

Mastering Linux File Time: From Getting Started to Practical Combat

mtime

mtime is the abbreviation of Modification Time. It means that when the "content data" is modified, the Linux system will update this time. For example: we use echo, vim and other instructions to write data to the file

Mastering Linux File Time: From Getting Started to Practical Combat

In the picture above, when we use the echo command to write a string to the test.txt file, we find that mtime and the ctime we are going to mention below have been changed. Let us first enter the following Use ctime to see why such a result is produced!

ctime

ctime is the status time in the Linux system, which is the status time. When the status of the file, that is, the attributes of the file, is changed, this time will be changed, such as links (number of links) and size (size of the file) in the file system. , file permissions, blocks (the number of blocks in the file); when these parameters are changed, Linux will change the time parameter corresponding to the file.

Mastering Linux File Time: From Getting Started to Practical Combat

Now you may understand why the ctime of the file was also changed when the mtime of the file was modified. Because when the content of the file is modified, the size of the file will definitely change, so The file's status time is updated as the file's contents are modified. So if the mtime of the file is modified, the ctime of the file will also be changed.

Other ways to view file time

1.ls -l –time=xx time file name;

This query method displays the mtime of the file by default.

2.ls -lx file name

In this query method
cctime
uatime
ls -lc filename lists the ctime (last modified time) of the file

ls -lu filename lists the atime (last access time) of the file

ls -l filename lists the mtime (last modification time) of the file

Summarize

In short, the file time in the Linux system is very important information, which can help us better manage and maintain files. Through the introduction of this article, we can clearly understand the concept, types and usage of file time. Mastering these skills is very helpful for better working and learning in the Linux field.

The above is the detailed content of Mastering Linux File Time: From Getting Started to Practical Combat. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:lxlinux.net. If there is any infringement, please contact admin@php.cn delete