我想从我的源创建一个符号链接:
/nfs/www/example.com/sourcefolder
到这个目的地:
/var/www/example.com/destinationfolder
所以我运行这个命令:
ln -s /nfs/www/example.com/sourcefolder /var/www/example.com/destinationfolder
我的问题:如果命令在目标文件夹中运行两次将是一个循环
/var/www/example.com/destinationfolder/sourcefolder/......./sourcefolder
我也测试过:
ln -s /dev/shm/ $APACHEHOME/tmp
所以我会有一个循环文件夹“shm”。问题是,网络应用程序需要将该文件夹命名为“tmp”,但它应该映射到内存。
我做错了什么?
答案1
尝试使用 -v 获得更详细的输出:
[root@centos7 ~]# mkdir /tmp/test/sourcefolder
[root@centos7 ~]# ls -l /tmp/test
total 0
drwxr-xr-x. 2 root root 6 Feb 21 11:40 sourcefolder
[root@centos7 ~]# ln -v -s /tmp/test/sourcefolder /tmp/test/destinationfolder
‘/tmp/test/destinationfolder’ -> ‘/tmp/test/sourcefolder’
[root@centos7 ~]# ls -l /tmp/test
total 0
lrwxrwxrwx. 1 root root 22 Feb 21 11:55 destinationfolder -> /tmp/test/sourcefolder
drwxr-xr-x. 2 root root 6 Feb 21 11:40 sourcefolder
链接循环是由于 ln 的行为造成的
[root@centos7 ~]# ln -v -s /tmp/test/sourcefolder /tmp/test/destinationfolder
‘/tmp/test/destinationfolder/sourcefolder’ -> ‘/tmp/test/sourcefolder’
[root@centos7 ~]# ls -l /tmp/test
total 0
lrwxrwxrwx. 1 root root 22 Feb 21 11:55 destinationfolder -> /tmp/test/sourcefolder
drwxr-xr-x. 2 root root 25 Feb 21 11:57 sourcefolder
[root@centos7 ~]# ls -l /tmp/test/sourcefolder
total 0
lrwxrwxrwx. 1 root root 22 Feb 21 11:57 sourcefolder -> /tmp/test/sourcefolder
尝试将目标文件夹解析为目录而不是已存在的符号链接。
您可以通过使用 -T 来避免这种情况:
[root@centos7 ~]# ln -v -T -s /tmp/test/sourcefolder /tmp/test/destinationfolder
‘/tmp/test/destinationfolder’ -> ‘/tmp/test/sourcefolder’
[root@centos7 ~]# ln -v -T -s /tmp/test/sourcefolder /tmp/test/destinationfolder
ln: failed to create symbolic link ‘/tmp/test/destinationfolder’: File exists