WSL:从Windows使用WSL符号链接文件夹

时间:2019-08-20 19:31:18

标签: symlink windows-subsystem-for-linux

我几乎只使用WSL,并且仅切换到用于浏览和运行Windows本机程序的主窗口。我在/mnt/c/myrepo有一个git存储库。为了“安装” /mnt/c/myrepo中的代码,我需要将其移至/mnt/c/otherlocation/renamed。我不想每次从cp -r /mnt/c/myrepo /mnt/c/otherlocation/renamed执行git pull时都执行/mnt/c/myrepo,而是想将/mnt/c/myrepo符号链接到/mnt/c/otherlocation/renamed。但是,当我这样做时,使用/mnt/c/otherlocation/renamed的程序无法查看重命名为目录的“内容”。

我遍历了WSL github存储库和问题跟踪器,试图为该问题找到解决方案。我对符号链接如何“正常工作”感到非常惊讶。我启用了我能找到的所有Windows 10开发人员功能,甚至还跟踪了一个reddit线程,有人声称购买Pengwin并从Pengwin创建符号链接可以确保这种兼容性,但是我仍然无法实现这一目的。

我需要的基本用法是允许我从Windows查看“重命名”为目录,或者让Windows将符号链接识别为符号链接目录。

来自wsl:

ln -s /mnt/c/myrepo  /mnt/c/otherlocation/renamed

从Windows:

  1. 打开文件浏览器
  2. 导航到c:\ otherlocation
  3. 打开mydir并像查看本地目录一样查看内容

我该怎么做?

2 个答案:

答案 0 :(得分:4)

此问题的解决方案是在声明链接时仅使用相对路径。如果要从Windows链接到Windows,则应相对于当前目录的路径,然后可以链接到所需的任何位置。

从示例开始,而不是这个:

ln -s /mnt/c/myrepo  /mnt/c/otherlocation/renamed

执行此操作:

cd /mnt/c/otherlocation
ln -s ../../myrepo ./renamed

答案 1 :(得分:0)

在Windows中的cmd.exe中执行符号链接:

mklink /d C:\otherlocation\renamed C:\myrepo

如果两个目录都在Windows中,则在WSL中创建符号链接是没有意义的。

此符号链接也将在WSL中工作。

致谢