Linux Study Notes Day 3 - Soft Links and Hard Links

Linux Softlinks and Hardlinks

In Linux, there are two kinds of links, soft links and hard links. There are some differences between the two links. Today, we will sort out their differences.

Difference between soft link and hard link
List the difference soft link hard link
1 start of file starts with l no regulations
2 permission lrwxrwxrwx (everyone has all permissions) uncertain
3 i node is different from the node of source file i

It is the same as the i-node of the source file, so the content modification of the source file and hard link is

Synchronized, of course, you can also see your changes when you run the soft link, because the soft link points to the source file.

4 across partitions Can span partitions Cannot cross partitions
5 link object Can link directories and files Can't link directory

In addition, there is one more thing to know. When the source file is deleted, it is invalid to execute the soft link at this time, which is equivalent to that in the window, your installation directory is no longer available. At this time, you click the shortcut again. It doesn't work, but the hard link is OK. Even if your source file has been deleted, the hard link can still be used. The hard link is like a backup, and the attributes are unchanged, which is equivalent to cp -p+ Synchronized modification. Here are some examples to demonstrate.

As shown in the figure, I used ln -s to create a soft link, and ln created a hard link. When I go to check their properties, I will find that the inode number of the soft link is different from the source file, while the hard link The i-node number is the same as the source file. Also, soft links start with l: lrwxrwxrwx, and everyone has full permissions.

Below I will demonstrate building links into different partitions

As shown in the figure, I want to build a hard link under the root partition, but his source file is under the boot partition, and an error will be reported at this time.

In addition to not being able to cross partitions, hard links cannot link directories

Hard links are not allowed to link to directories, even in the same location! !

ok finish work! !

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326995357&siteId=291194637