Nat*_*han 9 symlink windows-subsystem-for-linux
我几乎只使用 WSL,并且只切换到主窗口来浏览和运行 Windows 本机程序。我有一个 git 存储库位于/mnt/c/myrepo. 为了“安装”里面的代码,/mnt/c/myrepo我需要将它移动到/mnt/c/otherlocation/renamed. cp -r /mnt/c/myrepo /mnt/c/otherlocation/renamed我不想每次执行git pullfrom时都执行/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
Run Code Online (Sandbox Code Playgroud)
从窗口:
我该怎么做呢?
Do the symlink in Windows, in cmd.exe:
mklink /d C:\otherlocation\renamed C:\myrepo
Run Code Online (Sandbox Code Playgroud)
It doesn't make sense creating the symlinks in WSL if both directories are in Windows.
This symlink will work in WSL as well.
解决这个问题的方法很简单,就是在声明链接时使用相对路径。如果你想从windows链接到windows,你应该从当前目录相对路径,然后你可以链接到你想要的任何地方。
从示例中,而不是这样:
ln -s /mnt/c/myrepo /mnt/c/otherlocation/renamed
Run Code Online (Sandbox Code Playgroud)
做这个:
cd /mnt/c/otherlocation
ln -s ../../myrepo ./renamed
Run Code Online (Sandbox Code Playgroud)
由于这似乎是唯一一篇在从 Windows 到 WSL 搜索符号链接时具有任何 googlejuice 的 SO 帖子,我想我应该添加该问题的答案,即
如何创建适用于 Windows 应用程序的从 Windows 文件系统到 wsl 文件系统的“符号链接”?
答案在评论中,归功于@Mikepote
首先以管理员身份运行打开Powershell
然后运行
New-Item -ItemType SymbolicLink -Path "windows-path\to\symlink" -Target "\\wsl$\Ubuntu\home\yourusername\path\to\target-thing"
Run Code Online (Sandbox Code Playgroud)
Ubuntu如果有必要,显然也可以用您的发行版名称替换上面的名称yourusername。
| 归档时间: |
|
| 查看次数: |
15430 次 |
| 最近记录: |