Mac 上奇怪的软链接 ln 命令问题

Mac 上奇怪的软链接 ln 命令问题

我想创建/Library/Java/JavaVirtualMachines/jdk1.8.0_5.jdk/Contents/Home/指向真实目录的空目录/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home/,因为部分代码依赖于此特定版本的 JDK(1.8.0_5,但我只有 1.8.0_74),但 ln 命令失败并出现以下错误,您知道哪里出了问题吗?谢谢。

顺便说一句,我正在使用 Mac OSX。

ls -l /Library/Java/JavaVirtualMachines/
total 0
drwxr-xr-x  3 root  root  102 Jan 20 16:32 Contents
drwxr-xr-x  3 root  root  102 Jan 25 16:16 jdk1.8.0_05.jdk
drwxr-xr-x  3 root  root  102 Jan 25 16:15 jdk1.8.0_25.jdk
drwxr-xr-x  3 root  root  102 Jan 25 16:15 jdk1.8.0_40.jdk
drwxr-xr-x  3 root  root  102 Jan 20 16:32 jdk1.8.0_72.jdk
drwxr-xr-x  3 root  root  102 Feb  5 15:25 jdk1.8.0_74.jdk
ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_5.jdk/Contents/Home/ /Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home/
ln: /Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home//Home: File exists

更新,尝试了 Schlachter 的解决方案,但遇到了新的问题,

ls /Library/Java/JavaVirtualMachines
Contents        jdk1.7.0_51.jdk jdk1.8.0_25.jdk jdk1.8.0_72.jdk jdk1.8.0_77.jdk
jdk1.7.0_21.jdk jdk1.8.0_05.jdk jdk1.8.0_40.jdk jdk1.8.0_74.jdk

ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home /Library/Java/JavaVirtualMachines/jdk1.8.0_5.jdk/Contents/
ln: /Library/Java/JavaVirtualMachines/jdk1.8.0_5.jdk/Contents/: No such file or directory

答案1

只要jdk1.8.0_5.jdk/Contents/Home不存在,您就可以使用:

ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home /Library/Java/JavaVirtualMachines/jdk1.8.0_5.jdk/Contents/

末尾的斜杠Contents/表示将Home快捷方式放在文件夹内Contents。文件夹上没有斜杠,Home因为它是链接的目标。

编辑:链接所在的上述所有文件夹都需要存在。mkdir可以为您创建它/它们,例如mkdir -p /Library/Java/JavaVirtualMachines/jdk1.8.0_5.jdk/Contents

相关内容