What is the inode value in Linux?

Source: Internet
Author: User
What is the inode value in Linux-general Linux technology-Linux programming and kernel information, the following is a detailed description. Inode;

Inode is an index node. Partition of each storage device or storage device (the storage device is a hard disk, floppy disk, USB flash disk ......) after being formatted as a file system, there should be two parts: one part is inode, the other part 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-chain sun002.txt for sun.txt. Then, the attributes of sun.txtand sun002.txt are changed;

[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

After the consumer is created, the value is changed to 2. In other words, every time we create a new hard link file for sun.txt, the number of hard links increases 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.

2.12 create soft links and relationships between soft links and source files;

Syntax for creating soft links (also called symbolic links;

# Ln-s source file or directory target file or directory

A soft link is also called a symbolic link. It is different from a hard link. A Soft link file is only a mark of its source file. After the source file is deleted, the linked file cannot exist independently. Although the file name is retained, we cannot view the content of the soft link file.

[Root @ localhost ~] # Ls-li linuxsir001.txt

2408274-rw-r -- 1 root 29 04-22 21:53 linuxsir001.txt

[Root @ localhost ~] # Ln-s linuxsir001.txt linuxsir002.txt

[Root @ localhost ~] # Ls-li linuxsir001.txt linuxsir002.txt

2408274-rw-r -- 1 root 29 04-22 21:53 linuxsir001.txt

2408795 lrwxrwxrwx 1 root 15 04-22 linuxsir002.txt-> linuxsir001.txt

Explanation

In the above example, we first look at the attributes of linuxsir001.txt, such as inode, file type, creation or modification time, and so on ...... let's compare:

First, compare the nodes: the nodes of the two files are different;

Secondly, the types of the two files are different. linuxsir001.txtis a normal file, while linuxsir002.txt is a link file;

The read and write permissions of the third two files are different. linuxsir001.txt is rw-r --, and linuxsir002.txt is rwxrwxrwx.

The third two have the same number of hard links; both are 1

The owner and user group of the fourth two files are the same;

Fifth, the modification (or access or creation) takes different time;

We also listed a mark after linuxsir002.txt, which is the soft link file of linuxsir001.txt.

It is worth noting that when we modify the content of the link file, it means we are modifying the content of the source file. Of course, the attribute of the source file will also change, and the attribute of the linked file will not change. After the source file is deleted, only one file name exists in the linked file. Because the source file is lost, the soft link file does not exist. This is different from hard links;

[Root @ localhost ~] # Rm-rf linuxsir001.txt Note: delete linuxsir001.txt

[Root @ localhost ~] # Ls-li linuxsir002.txt Note: View linuxsir002 attributes;

2408795 lrwxrwxrwx 1 root 15 04-22 linuxsir002.txt-> linuxsir001.txt

[Root @ localhost ~] # More linuxsir002.txt Note: linuxsir002.txt content;

Linuxsir002.txt: the file or directory does not exist. Note: linuxsir002.txt does not exist.

The example above tells us that if a linked file loses its source, it means it does not exist;

We can see that the soft link file is actually a mark of the source file. When the source file is lost, it exists. Soft-link files only occupy inode to store soft-link file attributes and other information, but file storage points to the source file.

Software link, which can be applicable to files or directories. You can use rm to delete both soft and hard links. Rm tools are common.
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.