Differences between soft and hard links in Linux

Source: Internet
Author: User

For users who learn Linux operating systems, they may often see soft links and hard links. But do you know the differences between the two? This article explains the differences between the hardware and software links in Linux.

Differences between hard and soft links

1) soft connections can be used across file systems, but hard Connections cannot. The practice is to use a shared file to connect the aa.txt text file in windows to bb, cc. ln-s aa.txt/root/bb in the/root directory in Linux. Ln aa.txt/root/bb failed.

2) I node issues. No matter how many hard connections direct to the same I node, the number of connections at the node increases. As long as the number of connections at the node is not 0, the file will always exist, whether you delete the source file or the connected file. If only one object exists, there is actually no source file to connect to, because they all point to the same I node ). When you modify the source file or any connected file, other files will be synchronized. Soft links do not directly use the I node number as the file pointer, but use the file path name as the pointer. Therefore, deleting the connection file does not affect the source file. However, deleting the source file does not affect the file to be directed. The soft link has its own inode, and there is a small space on the disk to store the path name.

3) a soft connection can be used to connect a non-existent file name.

4) soft connections can be used to connect directories.

Note: I node: it is a data structure used within UNIX to describe file features. We usually call I a file index node (information node ). The I node contains most important information about the file, including the address of the file data block on the disk. Each I node has its own logo number, which is called the document sequence number. Information contained in the I node: 1. file type 2. File owner relationship 3. file access permission 4. File time cut.

Hard connection refers to the connection through the index node. In a Linux File System, a file stored in a disk partition is assigned with an Index node number (Inode Index) No matter what type it is ). In Linux, multiple file names direct to the same index node. Generally, this type of connection is hard connection.

A hard connection allows a file to have multiple valid path names. In this way, you can create a hard connection to an important file to prevent "accidental deletion. The reason is as described above, because there is more than one connection to the index node of the directory. Deleting only one connection does not affect the connection between the index node and other nodes. Only when the last connection is deleted will the connection of the data block and directory of the file be released. That is to say, the object will be deleted.

Soft-link files are similar to Windows shortcuts. It is actually a type of special file. In a symbolic connection, a file is actually a text file containing the location information of another file.

Soft link is another file, which can be understood as a pointer. Operations on this file, except deletion, are directly directed to the file. Because it is a real file, it occupies disk space. Hard links can be regarded as not a file. They are just an alias of an actual file. They are used to prevent misoperation of a real file. After a hard link is established for a file, they are aliases of each other, deleting any of these aliases will only delete the alias, and the actual file will not be deleted. Because only the alias does not have any other information, it does not occupy the disk space of the original file size.

Measure the test taker's knowledge about the differences between hardware and software links in Linux.

  1. Describes how to install a wireless NIC Driver in Linux.
  2. Wine successfully runs Bitcomet in the Linux operating system
  3. Analysis of Open-source Cisco router virtual machines in Linux
  4. Basic Linux operating system knowledge
  5. Learning Manual: poll and select in Linux

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.