Linux create connection command ln -s soft connection

lnThe function is to establish a synchronous link for a certain file in another location.
The most commonly used parameter of this command is -s, the
specific usage is: ln -s Source file Target file.

When the same file is used in different directories, there is no need to put a file that must be the same in every required directory, but only in a fixed directory, put the file, and then put it in other directories Use the ln command to link (link) it, and you don’t have to repeatedly take up disk space.
For example: ln -s /bin/hello.sh /usr/local/bin/hello-s is the meaning of the code (symbolic).

There are two points to note here:
first, the ln command will keep every link file synchronized, that is, no matter where you change, other files will have the same changes;
second, the ln link There are two kinds of soft links and hard links.
Soft links are that ln -s src dst,it will only generate a mirror image of a file in the location you selected, and will not occupy disk space.
Hard links ln src dst, without the parameter -s, will be in the location you selected. Generate a file with the same size as the source file, whether it is a soft link or a hard link, the file keeps changing synchronously.
Deletion of a connection:
Direct rm dst
Example :rm /usr/local/bin/hello

If you use ls to view a directory, and find that some files have a @symbol behind them, that is a file generated by the ln command, use the ls -lcommand to view, and you can see the displayed link path.

[email protected]:/tmp# ./hello.sh 
hello world
[email protected]:/tmp# ln -s /tmp/hello.sh /bin/shello
[email protected]:/tmp# shello
hello world
[email protected]:/tmp# ln /tmp/hello.sh /bin/hhello
[email protected]:/tmp# hhello
hello world
[email protected]:/tmp# rm -rf /bin/shello 
[email protected]:/tmp# shello
bash: /bin/shello: No such file or directory
[email protected]:/tmp# hhello
hello world
[email protected]:/tmp# rm -rf /bin/hhello 
[email protected]:/tmp# ./hello.sh 
hello world
[email protected]:/tmp# 

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *