今天想在Linux下覆盖一个目录的软连接,遇到点问题,所以总结了下发表这篇博文:
如果把原来的软连接删掉,重新创建一个软连接,那么inode节点会有变化,这不是我想要的,所以做了如下测试:
先看普通文本文件:覆盖文本文件的软连接就是用ln的-sf参数,-f是强制移除旧文件
[root@linuxidc tmp]# touch {1,2}
[root@linuxidc tmp]# ln -s 1 1.sym
[root@linuxidc tmp]# ll
total 12
-rw-r–r– 1 root root 0 Jan 9 10:51 1
lrwxrwxrwx 1 root root 1 Jan 9 10:51 1.sym -> 1
-rw-r–r– 1 root root 0 Jan 9 10:51 2
[root@linuxidc tmp]# ls -i 1.sym
622597 1.sym
[root@linuxidc tmp]# ln -s 2 1.sym
ln: creating symbolic link `1.sym’ to `2′: File exists
[root@linuxidc tmp]# ln -sf 2 1.sym
[root@linuxidc tmp]# ls -i 1.sym
622597 1.sym
[root@linuxidc tmp]# rm -f 1.sym
[root@linuxidc tmp]# ln -s 2 1.sym
[root@linuxidc tmp]# ls -i 1.sym
622596 1.sym
[root@linuxidc tmp]#
覆盖目录的软连接:ln -snf ,-n讲目标文件看成是普通文本文件,目标文件后面不要加/,否则加-n也不管用了。
[root@linuxidc tmp]# mkdir {a,b}
[root@linuxidc tmp]# ln -s a a.sym
[root@linuxidc tmp]# ll
total 32
-rw-r–r– 1 root root 0 Jan 9 10:51 1
-rw-r–r– 2 root root 0 Jan 9 10:51 1.sym -> 2
-rw-r–r– 2 root root 0 Jan 9 10:51 2
drwxr-xr-x 2 root root 4096 Jan 9 11:02 a
lrwxrwxrwx 1 root root 1 Jan 9 11:02 a.sym -> a
drwxr-xr-x 2 root root 4096 Jan 9 11:02 b
[root@linuxidc tmp]# ls -di a.sym
622599 a.sym
[root@linuxidc tmp]# ln -s b/ a.sym
[root@linuxidc tmp]# ll a.sym/
total 4
lrwxrwxrwx 1 root root 2 Jan 9 11:03 b -> b/
[root@linuxidc tmp]# ll
total 32
-rw-r–r– 1 root root 0 Jan 9 10:51 1
-rw-r–r– 2 root root 0 Jan 9 10:51 1.sym -> 2
-rw-r–r– 2 root root 0 Jan 9 10:51 2
drwxr-xr-x 2 root root 4096 Jan 9 11:03 a
lrwxrwxrwx 1 root root 1 Jan 9 11:02 a.sym -> a
drwxr-xr-x 2 root root 4096 Jan 9 11:02 b
[root@linuxidc tmp]# rm -f a.sym/b
[root@linuxidc tmp]# ln -sf b/ a.sym
[root@linuxidc tmp]# ll
total 32
-rw-r–r– 1 root root 0 Jan 9 10:51 1
-rw-r–r– 2 root root 0 Jan 9 10:51 1.sym -> 2
-rw-r–r– 2 root root 0 Jan 9 10:51 2
drwxr-xr-x 2 root root 4096 Jan 9 11:03 a
lrwxrwxrwx 1 root root 1 Jan 9 11:02 a.sym -> a
drwxr-xr-x 2 root root 4096 Jan 9 11:02 b
[root@linuxidc tmp]# ll a.sym
lrwxrwxrwx 1 root root 1 Jan 9 11:02 a.sym -> a
[root@linuxidc tmp]# ll a.sym/
total 4
lrwxrwxrwx 1 root root 2 Jan 9 11:03 b -> b/
[root@linuxidc tmp]# rm -f a.sym/b
[root@linuxidc tmp]# ln -snf b/ a.sym
[root@linuxidc tmp]# ll
total 32
-rw-r–r– 1 root root 0 Jan 9 10:51 1
-rw-r–r– 2 root root 0 Jan 9 10:51 1.sym -> 2
-rw-r–r– 2 root root 0 Jan 9 10:51 2
drwxr-xr-x 2 root root 4096 Jan 9 11:04 a
lrwxrwxrwx 1 root root 2 Jan 9 11:04 a.sym -> b/
drwxr-xr-x 2 root root 4096 Jan 9 11:02 b
[root@linuxidc tmp]# ls -di a.sym
622599 a.sym
ln 软连接目录 http://www.linuxidc.com/Linux/2013-01/77499.htm
本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-08/121285.htm