Tip: Let's first explain the basic storage of files and directories in the Linux system, which will make it easier for us to understand and learn hard links and soft links in the Linux system. 1. Basic storage of files and directories We have talked about partitions before. Each partition can be understood as being divided into two parts. A small part stores the The information stored in the i-node of a file includes: Each folder will have But there is a question, where is the file name of a file stored? Let's take a file In the In other words, the file name of the file in Where is the file name or The The root [root@192 ~]# ls -ild / 2 dr-xr-xr-x. 25 root root 4096 December 27 22:27 / The first digit displayed is the i-node number. Summarize To sum up, to view the contents of the 2. Introduction to In command(1) Let's take a look at the basic information of the ln command: The original meaning of (2) Basic format of the ln command[root@localhost ~] # ln [options] Source file target file options: -s: Create a soft link file. If the "-s" option is not added, a hard link file will be created. -f: forced. If the target file already exists, delete the target file and then create the link file. 3. Create a hard link(1) How to create a hard linkHere is an example: [root@localhost ~] # touch cangls [root@localhost ~ ]# ln /root/cangls /tmp/ # Create a hard link file. The target file does not have a file name, so it will be consistent with the original file. # That is, /root/cangls and /tmp/cangls are hard link files. Description # Create a new file abc and check the number of hard links of the abc file [root@192 ~]# touch abc [root@192 ~]# ls -il abc 1043285 -rw-r--r--. 1 root root 0 12月29 18:18 abc # You can see that the number of hard links of the abc file is 1. # Create a hard link file for the abc file in the tmp directory, and then check the number of hard links between the two files. [root@192 ~]# ln abc /tmp/abc_h [root@192 ~]# ls -il abc /tmp/abc_h 1043285 -rw-r--r--. 2 root root 0 12月29 18:18 abc 1043285 -rw-r--r--. 2 root root 0 12月29 18:18 /tmp/abc_h # You can see that the reference count (number of hard links) of the abc file has increased by 1. # You can also see that the i-node numbers of the two files above are the same. (2) Hard link features The source file and the hard link file have the same (3) Hard connection principle I created an Therefore, the See the picture below: So the above figure proves that: 4. Create a soft link(1) How to create a soft linkSoft links can be directly regarded as shortcuts in the Windows system. Create a soft link file as follows: [root@localhost ~]# touch abc [root@localhost ~]# ln -s /root/abc /tmp/ As shown in the following figure: [root@localhost ~ ]# touch cde [root@localhost ~ ] # ln -s /root/cde /tmp/cde_s [root@localhost ~ ] # ls -il /root/cde /tmp/cde_s 1055972-rw-r--r--1 root root 0 Feb 1715:30 /root/cde 261634 1rwxrwxrwx 1root root 9 Feb 1715:30 /tmp/cde_s->/root/cde illustrate: First: You can see that the created soft link file has a clear prompt that this is a soft link file and where its source file is located. Second: The number of citation links to the file did not increase. Third: The i-node numbers of the two files are completely different. Fourth: The source file (2) Soft link characteristics Soft links and source files have different (3) Soft connection principle There is a The Now the key is, what is stored in In fact, the As shown below: This also explains why the newly created soft link file has data after creation, and the data size does not change with the change of the source file. Another point to note is that the soft link file has the largest permissions, but this permission is for the soft link file. (4) DescriptionIn Windows, shortcuts are created because the software is installed too deep and difficult to find, so a shortcut is created on the desktop. What is the purpose of creating soft links in Linux? Anyway, they are all accessed through directories? In Linux systems, the main function of soft links is to take care of the administrator's usage habits. As shown below: In the old Linux system, we are used to the location of the Also note that a relative path is used to create a soft link to the From the above figure, you can see that an error occurs when creating a soft link with a relative path. Tip: When creating a soft link, be sure to use an absolute path; this is not required for a hard link. This is the end of this article about the detailed explanation of soft links and hard links in Linux. For more relevant content about Linux soft links and hard links, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: A brief discussion on group by in MySQL
>>: Comprehensive understanding of HTML Form elements
Win10 installation (skip if already installed) Fo...
Table of contents 1. Install the required environ...
Table of contents 1. Scenario Description 2. Solu...
Table of contents 1. Customize the search bar con...
ElasticSearch cluster supports動態請求的方式and靜態配置文件to ...
In the later stage of exploiting SQL injection vu...
Introduction MySQL 5.7 aims to be the most secure...
This article mainly introduces the pie chart data...
Searching online for methods to deploy Angular pr...
How much do you know about HTML? If you are learni...
Table of contents Achieve results Rolling load kn...
Copy code The code is as follows: <html> &l...
Lock classification: From the granularity of data...
The specific code is as follows: <!DOCTYPE htm...
Table of contents question extend Solving the pro...