Reprinted with attribution:
In Linux, a Symbolic Link is a special type of file link, similar to a shortcut in Windows. It allows a user to access another file or directory via a file path without having to have an actual copy of the original file or directory. Soft links refer to files or directories by their filenames, rather than by their physical locations.
I. Relevant grammar
The basic syntax of the soft-connect command is as follows:
ln -s [source file or directory] [softlink filename]
Among them.-s
option indicates the creation of a soft connection. If you do not add the-s
option, a hard link is created.
Second, create a soft connection:
- Example command:
ln -s /usr/local/bin/python3 /usr/bin/python
- Description: This command creates a file named
python
The softlink file that points to the/usr/local/bin/python3
This source file. When you create a soft connection, a soft connection name is created in the specified directory.
root@controller1:/usr/bin# ln -s /usr/local/bin/python2.7 /usr/bin/python4
root@controller1:/usr/bin#
##Execute again with an exception
root@controller1:/usr/bin# ln -s /usr/bin/python2.7 /usr/bin/python4 ln: failed to create symbolic link '/usr/bin/python4': File exists root@controller1:/usr/bin# root@controller1:/usr/bin# ln -s /usr/bin/python2.7 /usr/bin/python5 root@controller1:/usr/bin#
The correct soft connection creation is shown in green, the wrong one is shown in red.
Third, check the soft connections:
ls -l /usr/bin/python
- Description:This command will display the soft connection file
python
details, which contains the path to the source file for the softlink (/usr/local/bin/python3
) with an arrow symbol (->
) is separate from the name of the flexible connection.
root@controller1:/usr/bin# ls -l /usr/bin/python5
lrwxrwxrwx 1 root root 18 Dec 1 12:39 /usr/bin/python5 -> /usr/bin/python2.7
root@controller1:/usr/bin#
l
Indicates that this is a Symbolic Link.rwxrwxrwx
are the permissions of the softconnect (although these usually do not affect the behavior of the softconnect itself, but rather access to the target pointed to by the softconnect).- 1 is the number of links (for soft links, this value is usually not important).
user
is the owner of the flexible connection.user
is the user group to which the soft connection belongs.9
is the size (in bytes) of the softwire file itself, which is usually a very small value because the softwire just contains a path to the target.date
cap (a poem)time
is the last modification date and time of the soft connection.linkname
is the name of the flexible connection.-> targetpath
is the path to the destination file or directory to which the soft connection points.
IV. Delete soft links:
rm /usr/bin/python
- Description:This command will delete the soft link file
python
but does not affect the source file/usr/local/bin/python3
The presence of the