Linux system link---soft link

soft link

Soft link (Soft Link) is also called symbolic link (Symbolic Link). Soft link files in Linux are similar to shortcuts in Windows. The soft link file in linux is actually a special file, the file type is l. A soft link file can actually be understood as a text file. This file contains the location information content of the soft link pointing to another source file. Therefore, by accessing this "shortcut", you can quickly locate the source file pointed to by the soft link. entity.

Schematic: 
write picture description here

Order: 
ln -s 源文件 软链接文件

example

①Create a soft link. 
To create a soft link source file, it needs to exist, and the soft link file to be created cannot exist.

[root@ianLinux softlnTest]# ln -s ianfile ianfile_soft_link
  • 1

② The inode numbers of the source file and the soft link file are not the same, which indicates that the source file and the soft link file are not the same file. (not the same as hard link) 
write picture description here

③ Use readlink to see that the soft link contains the path of the source file.

[root@ianLinux softlnTest]# readlink ianfile_soft_link 
ianfile
  • 1
  • 2

write picture description here

④The content of the source file can also be read through the soft link file.

[root@ianLinux softlnTest]# cat ianfile
Soft Link studying.
[root@ianLinux softlnTest]# cat ianfile_soft_link 
Soft Link studying.
  • 1
  • 2
  • 3
  • 4

⑤Deleting the soft link has no effect, but if the source file is deleted, there will be flashes of white characters on a red background, and the soft link will be invalid. (not the same as hard link) 
write picture description here

summary

  1. Soft links are similar to Windows shortcuts (you can view their points through readlink).
  2. Execute the command ln -s 源文件 软链接文件to complete the creation of the soft link (the target does not exist).
  3. A soft link is similar to a text file, which stores the path of the source file and points to the file entity of the source file.
  4. Soft links and source files are different types of files and different files. The inodes are also not the same.
  5. The rm command can be used to delete soft link files.

  1. Deleting the source file, the soft link file still exists, but the content of the pointed source file path cannot be accessed. When it fails, it is generally a flashing reminder with white characters on a red background.

Reprinted to https://blog.csdn.net/codetz/article/details/52422312

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325700368&siteId=291194637