考虑以下文件夹结构:
.
??? test1
? ??? nested1
? ??? testfile11
? ??? testfile12
??? test2
??? nested1 -> /path/to/dir/test1/nested1
??? testfile21
Run Code Online (Sandbox Code Playgroud)
test2/nested1是目录的符号链接test1/nested1。我希望,如果是 cwd,..会解析为test2. 但是,我注意到了这种不一致:
$ cd test2/nested1/
$ ls ..
nested1 testfile11 testfile12
$ cd ..
$ ls
nested1 testfile21
Run Code Online (Sandbox Code Playgroud)
touch也表现得像ls在test1.
为什么..作为cd引用符号链接的父级的参数,而(所有?)其他人引用链接目录的父级?是否有一些简单的方法可以强制它引用相对于符号链接的路径?即“相反”的readlink?
# fictional command
ls $(linkpath ..)
Run Code Online (Sandbox Code Playgroud)
编辑:使用 bash