ln命令创建软连接及删除软连接

深度链接 / 2023-12-06 21:48:19 / 135

linux下使用如何ln命令创建软连接?以及如何删除软连接?

1、创建软连接

#创建目录a
[root@wrx test]# mkdir a
#在目录a下创建一个空文件
[root@wrx test]# touch a/1.txt
#查看a目录下的文件列表
[root@wrx test]# ls a/
1.txt
#建立软连接
# ln -s 源文件 目标文件
[root@wrx test]# ln -s a b
#查看当前目录下文件
[root@wrx test]# ll -l
total 4
drwxr-xr-x 2 root root 4096 Mar 26 10:21 a
lrwxrwxrwx 1 root root    1 Mar 26 10:21 b -> a
#查看目录b下的文件
[root@wrx test]# ls b/
1.txt
[root@wrx test]#

2、删除软连接

[root@wrx test]# ll -al
total 12
drwxr-xr-x   3 root root 4096 Mar 26 10:21 .
dr-xr-x---. 15 root root 4096 Mar 26 10:20 ..
drwxr-xr-x   2 root root 4096 Mar 26 10:21 a
lrwxrwxrwx   1 root root    1 Mar 26 10:21 b -> a
#删除软连接,删除命令使用rm,切记注意务把源文件删除
[root@wrx test]# rm b
rm: remove symbolic link `b'? y
[root@wrx test]# ls -al
total 12
drwxr-xr-x   3 root root 4096 Mar 26 10:26 .
dr-xr-x---. 15 root root 4096 Mar 26 10:20 ..
drwxr-xr-x   2 root root 4096 Mar 26 10:21 a
[root@wrx test]#