Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to resolve links to Linux files

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Today I want to show you how to parse Linux file links. The content of the article Xiaobian think good, now to share with you, think there is a need for friends can understand, hope to help everyone, the following with the idea of Xiaobian to read together.

In Linux system links are divided into two types: soft links, hard links, you can use the ls -l command to view file links, where the first character in the first column represents the type of file; and the following number represents the number of file connections.

Link concept:

Divided into soft links and hard links, file type is l

Hard link: ln source file destination file

soft link: ln -s source file destination file (destination file cannot exist in advance)

ln -s /root/ /tmp/root #Create a soft link to/root directory to readlink /tmp/root directory #indicate link to address touch test.sh #Create test data ln www.example.com/tmp/test.sh test.sh #Create hard link ll -i www.example.com/tmp/test.sh test.sh #Check the i node of two files

Hard Links:

Hard links are links through index nodes. In linux systems, it is normal and allowed for multiple file names to point to the same index node. In this case, files are called hard links. Hard links are equivalent to another entry of files. Hard links are established to prevent accidental deletion and have backup effects.

ln /etc/hosts /tmp/oldboy.host #For this file, create a hard link, also can say created a file new entry/tmp/oldboy.host link knowledge summary:

Multiple files with the same inode node number are hard linked to each other, creating a hard link equivalent to multiple entries in the file entity

The file entity will be deleted only if the source file and all corresponding hard link files are deleted. If one or more hard links of the source file are deleted, the file entity will not be deleted. When deletion succeeds, file data is possible to recover before the file location is reoccupied or fsck checked

Prevent important files from being deleted by mistake by creating hard links to files

Hard link files are ordinary files that can be deleted by rm

Static files (no process calls), files will be deleted when i_link is 0

Delete the source file, soft link file still exists, but can not find the file, will flash red and white

Multiple soft links point to the same file, but these soft links have different inode and belong to different files.

Soft link file type is l, hard link file type is the same as source file

Links to documents:

1. File can create hard links, increasing the entry of files, but hard links cannot be created across partitions

2. File can create soft links, but only in the sibling directory, out of the sibling directory invalid

3. In fact, the file name itself is a hard link and also a file entry.

For directory links

Directories cannot create hard links, directories can create soft links

Soft links to directories are often used in production scenarios, hard links are rarely used

Each directory will have two hard links,. Current directory,.. parent directory

Link Summary:

1. Create hard links for files, add file read data entries; create soft links for directories, you can directly enter directories through soft links

2. Delete the source file name, as long as there is a hard link to the source file in, through the hard link or access to the data, and not deleted, why?

When i_link = 0 and i_count = 0, it is like locking the file data into a small black room, being recycled and deleted.

3. Delete soft link, no effect on source file, delete source file name, soft link pointing to source file becomes invalid

4. Hard links point to the same inode, soft links have their own inode and block

The above is how to parse all the contents of the Linux file link, more and how to parse the Linux file link related content can be searched before the article or browse the following article to learn Ha! I believe that Xiaobian will add more knowledge to everyone, I hope you can support it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report