Detailed parsing of file attributes in Linux

Source: Internet
Author: User
Article Title: Detailed parsing of file attributes in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

1. Linux File Attribute Overview

The attributes of a Linux file or directory mainly include the node, type, permission mode, number of links, user and user group to which the file or directory belongs, and the last access or modification time;

[Root @ localhost ~] # Ls-lih

Total 104 K

2408949-rwxr-xr-x 1 root 7 04-21 12:47 lsfile. sh

2408830 drwxr-xr-x 2 root 4.0 K 04-21 mkuml-2004.07.17

2408260 drwxr-xr-x 2 root 4.0 K 04-21 mydir

2408258 lrwxrwxrwx 1 root 7 04-21 sun001.txt-> sun.txt

2408263-rw-r -- 2 root 11 04-20 14:17 sun002.txt

2408263-rw-r -- 2 root 11 04-20 sun.txt

Explanation:

Field 1: inode

Field 2: file types and permissions;

Field 3: Number of hard links;

Field 4: Owner;

Field 5: the group to which it belongs;

Field 6: file or directory size;

Field 7 and Field 8: Last access or modification time;

Field 9: file name or directory name

Take lsfile. sh as an example:

2408949-rwxr-xr-x 1 root 7 04-21 12:47 lsfile. sh

Inode value: 2408949

File type: the file type is-, indicating that this is a common file. For file types, see Linux File Types and file extensions.

File Permission: The File Permission is rwxr-xr-x, which indicates that the file owner is readable, writable, and executable. the user group to which the file belongs is readable and executable, while other users are readable and executable;

Number of hard links: there is no hard link to the lsfile. sh file, because the value is 1, it is itself;

File owner: that is, the user to which the file belongs. It is root, that is, the first root;

File Group: that is, the user group to which the file belongs is the root user group;

File size: the file size is 7 bytes;

Time when access can be modified: the time here is the last access time. The time when the last access and file are modified or created is sometimes not the same;

Of course, the attributes of the document include not only these attributes, which are the most common attributes. Let's talk about more important things, such as the types, permissions, and number of hard links of files ...... ......

2. About inode

Inode is an index node. Partition of each storage device or storage device (the storage device is a hard disk, floppy disk, USB disk ...... ...... After being formatted as a file system, there should be two parts: one is inode, the other is Block, and the Block is used to store data. Inode is used to store the data information, including the file size, owner, owner user group, and read/write permissions. Inode indexes information for each file, so there is an inode value. Based on commands, the operating system can find the corresponding files with the fastest inode value.

To make a metaphor, for example, a book, a storage device or partition is equivalent to this book. Block is equivalent to every page in the book, and inode is equivalent to the directory before this book. A book has a lot of content, if you want to find a part of the content, you can first check the directory to find the content we want to see as quickly as possible. Although not appropriate, it is still a relatively good image.

When we use ls to view a directory or file, if we add the-I parameter, we can see the inode node. For example, we mentioned above;

[Root @ localhost ~] # Ls-li lsfile. sh

2408949-rwxr-xr-x 1 root 7 04-21 12:47 lsfile. sh

The inode value of lsfile. sh is 2408949. To view inode of a file or directory, use the-I parameter of the ls command.

2.10 files with the same inode are hard-linked files;

In a Linux File System, files with the same inode value are hard-linked files, that is, different file names may have the same inode, and one inode value may correspond to multiple files. It is not difficult to understand the link file. Just look at the example. In Linux, the link file is created using the ln tool.

2.11 create a hard link, a hard link, and a source file relationship;

Syntax for creating a hard link with ln:

# Target ln source file

Let's take an example. In this example, we want to create a hard link to sun002.txt.for sun.txt and then refer to the changes in attributes of sun.txtand sun002.txt;

[Root @ localhost ~] # Ls-li sun.txt Note: Attributes of sun.txt;

2408263-rw-r -- 1 root 29 04-22 sun.txt Note: This is the property of sun.txt;

[Root @ localhost ~] # Ln sun.txt sun002.txt note: we use ln to create sun.txt's hard chain file sun002.txt

[Root @ localhost ~] # Ls-li sun * Note: we have two columns: sun.txt and sun002.txt.

2408263-rw-r -- 2 root 29 04-22 21:02 sun002.txt

2408263-rw-r -- 2 root 29 04-22 21:02 sun.txt

Worker after creating a new hard link file, the number of hard links will increase by 1.

Files with the same inode value have a hard link to each other. When we modify the content of a file, the content of the file that is hard-linked to each other also changes. If we delete a file that is hard-linked to each other, other files will not be affected. For example, if we delete sun.txt, we can see the content of sun002.txt, and sun02.txt still exists.

It can be understood that files with hard links are like clones, and their attributes are almost identical;

In the example below, we delete sun.txt, and then we can see whether sun002.txt can be seen.

[Root @ localhost ~] # Rm-rf sun.txt

[Root @ localhost ~] # More sun002.txt

Note: hard links cannot be created for directories. Only files can be created for hard links.

[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] Next page

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.