简体   繁体   English

如何在不遵循符号链接的情况下创建指向另一个符号链接的符号链接,同时保持相对路径?

[英]How to create symlink to another symlink without following symlink while keeping relative path?

How to create a symlink to another symlink without following target symlink but keeping relative path between the target symlink and created symlink?如何在不遵循目标符号链接但保持目标符号链接和创建的符号链接之间的相对路径的情况下创建指向另一个符号链接的符号链接?

Using the following structure for test使用以下结构进行测试

├── dst
│   
└── src
    ├── file.txt -> folder/file.txt
    └── folder
        └── file.txt


lrwxrwxrwx 1 user group 15 mars  16 20:05 src/file.txt -> folder/file.txt

Each time I try to create a symlink of src/file.txt (itself a relative symlink of src/folder/file.txt ) in dst folder, the resulting symlink is never like dst/file.txt ->../src/file.txt but always directly to the final target dst/file.txt ->../src/folder/file.txt每次我尝试在dst文件夹中创建src/file.txt的符号链接(本身是src/folder/file.txt的相对符号链接)时,生成的符号链接永远不会像dst/file.txt ->../src/file.txt但总是直接指向最终目标dst/file.txt ->../src/folder/file.txt

ln -s -r [-T] 'src/file.txt' dst/file.txt

Only working without -r and specifying myself the relative path仅在没有-r的情况下工作并为自己指定相对路径

ln -s '../src/file.txt' dst/file.txt

I need to use this inside a for loop for many files recursively and I would like to keep a relative path between the symlinks but without following target symlink, just a relative symlink to another symlink.我需要在 for 循环中对许多文件递归地使用它,我想在符号链接之间保留相对路径,但不遵循目标符号链接,只是到另一个符号链接的相对符号链接。

Is it possible to use ln with -r relative option without following target symlink?是否可以在不遵循目标符号链接的情况下将ln-r相对选项一起使用?

Regards问候

Seems like ln -s -r follows links..好像ln -s -r跟随链接..

Without the -r option ln -s puts in exactly what you type - so later the other link can be changed and the first directory still works.如果没有-r选项ln -s会准确输入您键入的内容 - 因此稍后可以更改另一个链接并且第一个目录仍然有效。

# mkdir ABC
# mkdir DEF
# touch DEF/xx.txt
# ls -lAF DEF
total 8
drwxr-xr-x. 2 root root 4096 2021-03-17 11:40 ./
drwxrwxrwt. 4 root root 4096 2021-03-17 11:40 ../
-rw-r--r--. 1 root root    0 2021-03-17 11:40 xx.txt
# ln -s DEF/xx.txt 
# ls -laF
total 16
drwxrwxrwt.  4 root root 4096 2021-03-17 11:40 ./
drwxr-xr-x. 21 root root 4096 2017-03-17 14:13 ../
drwxr-xr-x.  2 root root 4096 2021-03-17 11:40 ABC/
drwxr-xr-x.  2 root root 4096 2021-03-17 11:40 DEF/
lrwxrwxrwx.  1 root root   10 2021-03-17 11:40 xx.txt -> DEF/xx.txt
# cd ABC/
# ln -s ../xx.txt 
# ls -laF
total 8
drwxr-xr-x. 2 root root 4096 2021-03-17 11:40 ./
drwxrwxrwt. 4 root root 4096 2021-03-17 11:40 ../
lrwxrwxrwx. 1 root root    9 2021-03-17 11:40 xx.txt -> ../xx.txt
# echo "ABC" > DEF/xx.txt
# cat ABC/xx.txt
ABC

So all the soft links are soft-links to another soft-link or the file - not resolved all the way through.所以所有的软链接都是指向另一个软链接或文件的软链接 - 没有一直解析。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM