ka@karl:~$ ls ./test_source_sym
file.txt
ka@karl:~$ ln -s ./test_source_sym ./test_sym/dir
ka@karl:~$ ls -la ./test_sym/dir
lrwxrwxrwx 1 karl karl 17 jun 28 09:56 ./test_sym/dir -> ./test_source_sym
ka@karl:~$ cat ./test_sym/dir/file.txt
cat: ./test_sym/dir/file.txt: No such file or directory
我是否对符号链接有什么误解?
答案1
$ ln -s ./test_source_sym ./test_sym/dir
$ ls -al ./test_sym/dir
lrwxrwxrwx 1 user1 users 17 jun 28 18:25 ./test_sym/dir -> ./test_source_sym
这是错误目录的链接;它应该是父目录
$ rm ./test_sym/dir
$ ln -s ../test_source_sym ./test_sym/dir
$ ls -al ./test_sym/dir
lrwxrwxrwx 1 user1 users 18 jun 28 18:25 ./test_sym/dir -> ../test_source_sym
$ cat ./test_sym/dir/file.txt
hello world!
当你第一次进入 test_sym 目录时更容易理解:
$ rm ./test_sym/dir
$ cd test_sym
$ ln -s ../test_source_sym dir
$ ls -al
total 16
drwxr-xr-x 145 user1 users 12288 jun 28 18:23 ..
lrwxrwxrwx 1 user1 users 18 jun 28 18:31 dir -> ../test_source_sym
drwxr-xr-x 2 user1 users 4096 jun 28 18:31 .
$ cat dir/file.txt
hello world!
答案2
德普
- 确保
./test_source_sym
目录存在 - 确保
./test_sym
目录存在 ln -s ./test_source_sym/* ./test_sym
答案3
我不能 100% 确定为什么会出现这种情况,但我能够通过执行以下操作复制后解决您的问题:
steven:~/.tmp$ ls ./test_source_sym
file.txt
steven:~/.tmp$ mkdir test_sym
steven:~/.tmp$ cd test_sym
steven:~/.tmp/test_sym$ ln -vs ~/.tmp/test_source_sym dir
'dir' -> '/home/steven/.tmp/test_source_sym'
steven:~/.tmp/test_sym$ cat dir/file.txt
This is a file with text in it.
Line 2 of text.
3
Last line, goodbye!
似乎是ln
命令确定完整路径时出现问题test_source_sym
,因此无法创建指向该目录的正确符号链接。使用彩色输出显示ls
使用您的方法创建的符号链接已损坏。
希望这可以帮助!