Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 为什么ln-s中的尾部斜杠很重要?_Linux_Bash_Shell_Symlink - Fatal编程技术网

Linux 为什么ln-s中的尾部斜杠很重要?

Linux 为什么ln-s中的尾部斜杠很重要?,linux,bash,shell,symlink,Linux,Bash,Shell,Symlink,假设我想在桌面上创建一个指向文档文件夹的符号链接。我会这样做: cd ~/Desktop ln -s ~/Documents 这将在我的桌面上创建一个名为Documents的符号链接 但是,当我这样做时(请注意~/Documents后的尾随斜杠): cd ~/Desktop ln -s ~/Documents/ 我得到: ln: ./: File exists 为什么?为什么在这种情况下,尾随斜杠很重要?尾随斜杠通常意味着什么?如评论中所述,尾随斜杠取决于应用程序。在我的系统(CentOS

假设我想在桌面上创建一个指向文档文件夹的符号链接。我会这样做:

cd ~/Desktop
ln -s ~/Documents
这将在我的桌面上创建一个名为Documents的符号链接

但是,当我这样做时(请注意
~/Documents
后的尾随斜杠):

cd ~/Desktop
ln -s ~/Documents/
我得到:

ln: ./: File exists

为什么?为什么在这种情况下,尾随斜杠很重要?尾随斜杠通常意味着什么?

如评论中所述,尾随斜杠取决于应用程序。在我的系统(CentOS 5)上,两者都工作得很好

在这种情况下,我认为ln将
~/Documents/
解释为一个路径,并使用默认文件名
引用当前目录,以获得有效的
~/Documents/
组合路径。因为您没有指定目标链接的名称,所以它会选择与“单独指定”文件匹配的路径我,
,已经存在

当我显式地指定
~/Documents/
时,我会遇到与您类似的错误


您可以通过显式指定要创建的链接的名称来解决此问题。
ln-s~/Documents/Documents
应该适合您。

尾随斜杠的含义取决于应用程序。在Unix上可能相同: