Differences between Linux hard and soft links

Source: Internet
Author: User

For a file, there is a unique index contact (inode) corresponding to it, but for an index contact number, there can be multiple file names corresponding to it. Therefore, the same file on the disk can be accessed through different paths. Note that in Linux, everything is file. folders and newly added hard disks can all be processed by looking at the files.
A soft connection or a hard link is also called a symbolic link. Symbolic connections are equivalentWindows.
* ************************** You cannot create a hard connection to a folder or directory, we usually use more soft connections.

Eg:
Ln-S source Dist # establish a soft connection
Ln source Dist # establish a hard connection
 
What are the differences between them? The last time I read it well, it seems that it has something to do with the structure of the file system. I didn't have much detailed research. I'll see it again later.

----------------------
A soft link is actually just a piece of text that contains the name of the file it points to. The system automatically jumps to the corresponding file location after seeing the soft link. On the contrary, A hard link opens a new directory for a file. The hard link is equivalent to the original name of the file. in Linux, they are equivalent. For this reason, hard links cannot connect files on two different file systems.
 
The shortcut for soft connection is similar to that for Windows

As for hard connection, for example, if you hard connect dir1/file1 to dir2/file2, the image file file2 of dir1/file1 is created under dir2, it occupies as much space as file1, and changes one of the two, the other will also change.

Soft connection and hard connection can be understood as follows:
A hard connection is like a file with multiple file names,
A soft connection is used to generate a new file (the content of this file is actually the information of the original file path to be linked). This file points to the location of another file,
Hard connections must be in the same file system, while soft connections can be used across file systems.

Hard connection: both the source file name and the link file name point to the same physical address, and the directory cannot have a hard connection. The file has only one copy in the disk, which can save hard disk space, because deleting a file can be successful only when the same index node is a unique connection, it can prevent unnecessary accidental deletion of soft connections (symbolic connections) by using the Ln-s command to create a symbolic connection for the file, symbolic connection is a special file in Linux. As a file, its data is the path name of the file it connects to, similar to the hardware method, * ***** you can delete the original file and the connected file still exists. ********

 
This article attempts to clearly and thoroughly explain the differences between soft links and hard-link files
1. linked file
There are two methods for linking: Soft link and hard link.
1. Soft link file
Soft links are also called symbolic links. This file contains the path name of another file. It can be any file or directory that can be linked to files of different file systems.
* ********* A linked file can even link a file that does not exist, which leads to a problem (or "Symptom") that is generally called "broken chain "), you can even link yourself to a linked file. Similar to recursion in programming languages.
You can use the Ln-s command to generate a soft connection, as shown below:
[Root @ linux236 test] # ln-s source_file softlink_file
When reading or writing a symbolic file, the system automatically converts the operation to an operation on the source file. However, when deleting a linked file, the system only deletes the linked file, instead of deleting the source file.
2. Hard link file
The info ln Command tells you that a hard link is another name of an existing file (a "hard link" is another name for an existing file), which is somewhat confusing. The hard connection command is
Ln-D existfile newfile
There are two restrictions on hard-link files
1) hard links cannot be created for directories;
2) hard links can be created only between files in the same file system.
* *********** When performing read/write or delete operations on hard-link files, the results and soft links are the same. However, if we delete the source file of the hard link file, the hard link file still exists and retains the expected content.
* ********* At this time, the system "forgot" that it was a hard-linked file. And regard it as a common file.
The difference between the two
Hard connection refers to the connection through the index node. In a Linux File System, an index node number is assigned to a file stored in a disk partition regardless of its type ).
In Linux, multiple file names direct to the same index node. Generally, this type of connection is hard connection. * ****** Hard connection is used to allow a file to have multiple valid pathnames, so that you can establish a hard connection.
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.
After the connection is deleted, the data block and directory connection of the file will 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.
Three experiences
A soft link is another file and its function can be understood as a pointer. The operations on this file, except for deleting the file, are directly directed to the file, disk Space is occupied because it is a real file
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, delete any of them,
In this way, the RM command will only delete the alias, and the actual file will not be deleted. The original file is deleted only when the number of links is 0.

For a file, there is a unique index contact (inode) corresponding to it, but for an index contact number, there can be multiple file names corresponding to it. Therefore, the same file on the disk can be accessed through different paths. Note that in Linux, everything is file. folders and newly added hard disks can all be processed by looking at the files.
A soft connection or a hard link is also called a symbolic link. Symbolic connections are equivalentWindows.
* ************************** You cannot create a hard connection to a folder or directory, we usually use more soft connections.

Eg:
Ln-S source Dist # establish a soft connection
Ln source Dist # establish a hard connection
 
What are the differences between them? The last time I read it well, it seems that it has something to do with the structure of the file system. I didn't have much detailed research. I'll see it again later.

----------------------
A soft link is actually just a piece of text that contains the name of the file it points to. The system automatically jumps to the corresponding file location after seeing the soft link. On the contrary, A hard link opens a new directory for a file. The hard link is equivalent to the original name of the file. in Linux, they are equivalent. For this reason, hard links cannot connect files on two different file systems.
 
The shortcut for soft connection is similar to that for Windows

As for hard connection, for example, if you hard connect dir1/file1 to dir2/file2, the image file file2 of dir1/file1 is created under dir2, it occupies as much space as file1, and changes one of the two, the other will also change.

Soft connection and hard connection can be understood as follows:
A hard connection is like a file with multiple file names,
A soft connection is used to generate a new file (the content of this file is actually the information of the original file path to be linked). This file points to the location of another file,
Hard connections must be in the same file system, while soft connections can be used across file systems.

Hard connection: both the source file name and the link file name point to the same physical address, and the directory cannot have a hard connection. The file has only one copy in the disk, which can save hard disk space, because deleting a file can be successful only when the same index node is a unique connection, it can prevent unnecessary accidental deletion of soft connections (symbolic connections) by using the Ln-s command to create a symbolic connection for the file, symbolic connection is a special file in Linux. As a file, its data is the path name of the file it connects to, similar to the hardware method, * ***** you can delete the original file and the connected file still exists. ********

 
This article attempts to clearly and thoroughly explain the differences between soft links and hard-link files
1. linked file
There are two methods for linking: Soft link and hard link.
1. Soft link file
Soft links are also called symbolic links. This file contains the path name of another file. It can be any file or directory that can be linked to files of different file systems.
* ********* A linked file can even link a file that does not exist, which leads to a problem (or "Symptom") that is generally called "broken chain "), you can even link yourself to a linked file. Similar to recursion in programming languages.
You can use the Ln-s command to generate a soft connection, as shown below:
[Root @ linux236 test] # ln-s source_file softlink_file
When reading or writing a symbolic file, the system automatically converts the operation to an operation on the source file. However, when deleting a linked file, the system only deletes the linked file, instead of deleting the source file.
2. Hard link file
The info ln Command tells you that a hard link is another name of an existing file (a "hard link" is another name for an existing file), which is somewhat confusing. The hard connection command is
Ln-D existfile newfile
There are two restrictions on hard-link files
1) hard links cannot be created for directories;
2) hard links can be created only between files in the same file system.
* *********** When performing read/write or delete operations on hard-link files, the results and soft links are the same. However, if we delete the source file of the hard link file, the hard link file still exists and retains the expected content.
* ********* At this time, the system "forgot" that it was a hard-linked file. And regard it as a common file.
The difference between the two
Hard connection refers to the connection through the index node. In a Linux File System, an index node number is assigned to a file stored in a disk partition regardless of its type ).
In Linux, multiple file names direct to the same index node. Generally, this type of connection is hard connection. * ****** Hard connection is used to allow a file to have multiple valid pathnames, so that you can establish a hard connection.
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.
After the connection is deleted, the data block and directory connection of the file will 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.
Three experiences
A soft link is another file and its function can be understood as a pointer. The operations on this file, except for deleting the file, are directly directed to the file, disk Space is occupied because it is a real file
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, delete any of them,
In this way, the RM command will only delete the alias, and the actual file will not be deleted. The original file is deleted only when the number of links is 0.

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.