Detailed explanation of file time attribute in Linux File System

Source: Internet
Author: User

Directory
Overview
Overview of linux File Time Attributes
Detailed description of various Time Attributes

Recommended reading:

Common commands for Linux file systems and file operations

Linux File System limits ulimit usage

Linux File System Overview

A file is the basic structure for storing data in linux. It is stored in storage media such as hard disk, CD, and floppy disk, and is named. The name is the file name. Files in linux are non-structured streams.

There are many files in linux, which are managed and classified by inverted tree directory structure. A directory is an inverted tree structure that organizes and describes MetaData. The entire linux File System has a root/(root). When it is followed by a branch, the split plug can generate a branch, and the branch can also grow leaves. The root and fork are the directories in the linux File System, and the leaves are files. Access and operate files through the file path.

Linux File time attribute Overview

After files and directories are created and modified, their attributes change, with the time attribute. You can use commands such as ls OR stat to view the metadata of files and directories. The time attribute of a file is divided into three parts: File Access time, modification time, and change. Let's take a look at the specific situation under which the attribute changes. In linux, the time attribute of a file is represented by a struct. As follows:
1: struct stat {
2: dev_t st_dev;/* device inode resides on */
3: ino_t st_ino;/* inode's number */
4: mode_t st_mode;/* inode's mode */
5: nlink_t st_nlink;/* number of hard links to the file */
6: uid_t st_uid;/* user ID of owner */
7: gid_t st_gid;/* group ID of owner */
8: dev_t st_rdev;/* device type, for special file inode */
9: struct timespec st_atimespec;/* time of last access */
10: struct timespec st_mtimespec;/* time of last data modification */
11: struct timespec st_ctimespec;/* time of last file status change */
12: off_t st_size;/* file size, in bytes */
13: int64_t st_blocks;/* blocks allocated for file */
14: u_int32_t st_blksize;/* optimal file sys I/O ops blocksize */
15: u_int32_t st_flags;/* user defined flags for file */
16: u_int32_t st_gen;/* file generation number */
17 :};

Time Attributes of linux Files

Linux File time attributes include access time, modification time modifed time, and change time.

File access time

After a file is created, the file has the same access time, modification time modifed time, and change time. However, after some changes are made to the file, the time may change.

File access time, that is, the file content is read. If the file is viewed, the File Viewing Time is updated. For example, after cat, more, and less operations, the file access time is updated.

The following uses ls to display the file modification time modifed time by default.

Use the stat command to view more precise time attribute information

We can see that the file access time is 17:07:15. 000000000 + 0800. Let's see the content of this file less. Exit after less. We can see that the access time attribute of this file has changed.

File modification time modifed time

The modification time of the file is the modification time of the file content. For example, after modifying the file content through vim or emacs, or appending other methods, the file modification time will change.

The following example adds and modifies the file content, and the modification time of the file changes accordingly.

File change time

The file change time is the change time of other attributes of the file. For example, the file access time is updated when the attributes of files (ignoring changes in the file access time attribute and file modification time attribute) are changed through chmod, chown, ln, and so on. The chmod and chown update files are brand new, and the ln Update file's soft and hard link property information.

The following example creates a hard link to change the File Change Time:

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.