Create soft link
In Linux, you can use ln -s [源文件] [软链接文件]
the command to create soft links.
-
First, open the terminal and enter the target path. You can use
pwd
the command to view the current path. -
Use
mkdir
the command to create atest
directory named and usetouch
the command to create two test files in that directory, namedtest.txt
andval.txt
.mkdir test touch test/test.txt touch test/val.txt
-
Next, we will create a
test
soft link to the directory, using the following command:ln -s test test_chk_ln
-
After completing the creation of soft links, you can use the
ll
orls -l
command to view all files, including soft links.ll
Modify soft link
To modify the source file or directory pointed to by a soft link, you can use the following command:
ln -snf [新的源文件或目录] [软链接文件]
Make sure to replace [新的源文件或目录]
and [软链接文件]
with the actual path and filename.
Delete soft link
When deleting soft links, make sure to use the correct method to avoid accidentally deleting the actual associated data.
-
Correct way to delete (only delete soft links):
rm -rf ./test_chk_ln
To prevent accidental deletion, you can ask whether to delete the soft link:
rm -ri ./test_chk_ln
-
Wrong deletion method (the content pointed to by the soft link will also be deleted):
rm -rf ./test_chk_ln/
It is recommended that before performing any deletion operation, confirm whether you want to delete soft links or actual data, and proceed with caution to avoid data loss.
The article is reprinted in: Programming Log