Linux hard link and soft link

hard link

1. A file name contained in a directory is a hard link to a file, or Link for short. In the same directory or in different directories, the same file can have several links, corresponding to several file names.

Command to create a link: ln P1 P2

Used to create a new hard link, that is, create a hard link with the path name P2 for the file identified by the path P1.

Example:

Repeatedly creating hard links with the same name in the same directory will report an error:

 Hard link restrictions:

1. Users are not allowed to create hard links to directories.

2. Hard links can only be created between files in the same file system.

soft link

1. Soft link: also known as a symbolic link, which is a short file and can contain any path name of another file. The path name can point to any file or directory located in any file system, or even point to a file that does not exist.

Instructions for creating soft links: ln -s P1 P2

That is, create a new soft link with the path name P2, and P2 points to the path name P1. In this way, all references to P2 can be automatically converted into a reference to P1.

Example:

 A soft link can be created for a hard link.

like:

 You can also create a soft link for a soft link

 

Finally, you can also create a hard link for a soft link

 

Guess you like

Origin blog.csdn.net/xipengbozai/article/details/119990511