V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
yulihao
V2EX  ›  程序员

意外发现个 Windows 访问 WSL 下文件的方法

  •  
  •   yulihao · Jan 25, 2020 · 9290 views
    This topic created in 2296 days ago, the information mentioned may be changed or developed.
    CMD,输入 bash
    然后任务管理器--详细信息--bash--右键打开文件所在位置



    然后,就显示出了 WSL 下的所有文件
    不知道是不是暂时的
    不用 mnt 那么麻烦
    Supplement 1  ·  Jun 1, 2020
    这方法不靠谱,之前在 Windows 这边用 Noptepad 改了配置文件,Linux 那边不认,还得用 nano 再改一遍。

    微软开发者明确标红:
    DO NOT, under ANY circumstances, access, create, and/or modify Linux files inside of your `%LOCALAPPDATA%` folder using Windows apps, tools, scripts, consoles, etc.
    详见 https://devblogs.microsoft.com/commandline/do-not-change-linux-files-using-windows-apps-and-tools/

    正确的姿势:
    升级到 Windows 10 version 1903 或更新版本
    在 WSL bash 中,运行`explorer.exe .`打开资源管理器,来访问 WSL 中的文件,文件路径如\$wsl\Ubuntu\etc\nginx\nginx.conf (暂不支持符号链接,已经反馈提议支持符号链接)


    谢谢 @fuweichin 的提醒,不然我还真的把这帖子忘了
    19 replies    2020-06-01 01:35:07 +08:00
    venster
        1
    venster  
       Jan 25, 2020 via iPhone   ❤️ 5
    坐等权限混乱
    Carseason
        2
    Carseason  
       Jan 25, 2020 via iPhone
    wsl 本来就可以自定义安装,然后自己选个安装位置就可以了,
    你在 win 直接操作 wsl 文件会有权限问题的
    ragnaroks
        3
    ragnaroks  
       Jan 25, 2020
    不要直接读写此文件夹
    kindjeff
        4
    kindjeff  
       Jan 25, 2020 via Android
    wsl 是可以运行 exe 的,直接在 wsl 里`explorer.exe .`就完事了

    然而 Windows 里不能直接修改 wsl 文件系统里的文件,这也导致想在 Windows 版 docker 里挂载 wsl 目录进去进行修改是成功不了的
    oott123
        5
    oott123  
       Jan 25, 2020   ❤️ 3
    在有 wsl 进程开启的时候,可以直接
    开始-运行 \\wsl$
    katsusan
        6
    katsusan  
       Jan 25, 2020 via iPhone
    不仅如此,还可以修改注册表来把 wsl 转移到其他分区
    liaojl
        7
    liaojl  
       Jan 25, 2020
    alias wf='explorer.exe .'
    wf(Windows File)
    Wh1t3zZ
        8
    Wh1t3zZ  
       Jan 25, 2020   ❤️ 1
    VsCode 有个 remote-WSL 插件挺好用的,只是如果用 VsCode 界面新建文件的话权限会是 777,从终端用命令创建就正常了
    deorth
        9
    deorth  
       Jan 25, 2020
    这里删文件会导致两边文件系统不一致,强烈建议使用\\wsl$
    yulihao
        10
    yulihao  
    OP
       Jan 25, 2020
    @kindjeff 实测可以
    yulihao
        11
    yulihao  
    OP
       Jan 25, 2020
    @deorth 哦,明白了
    ps1aniuge
        12
    ps1aniuge  
       Jan 25, 2020
    5 楼正解
    Osk
        13
    Osk  
       Jan 25, 2020   ❤️ 1
    不瞒你说, 微软官方教程是这样的:
    下载 wsl 发行版 appx 包, 改名 zip 解压出来文件, 直接运行解压后的 ubuntu.exe 即可安装到当前目录.

    不过呢, 建议不要在资源管理器里面直接操作 wsl 的文件, 否则炸了自己负责.

    对了, wsl 居然不支持 ReFS... 服了
    mxalbert1996
        14
    mxalbert1996  
       Jan 25, 2020 via Android
    @yulihao 这里的不能不是做不到而是做了会出问题,记得很久以前有一次我在 Win 下修改了 rootfs 里的文件然后重启以后 WSL 就找不到这个文件了
    binbinyouliiii
        16
    binbinyouliiii  
       Jan 26, 2020
    添加网络位置 “\\wsl$\{你的 WSL 版本}”
    yousabuk
        17
    yousabuk  
       Jan 26, 2020 via iPhone
    我觉得 MSYS2 更好用
    linvaux
        18
    linvaux  
       Jan 30, 2020
    不推荐你这么玩
    fuweichin
        19
    fuweichin  
       Jun 1, 2020
    楼主是否考虑修改文章内容?继续下去可能会误导一些人。

    这方法不靠谱,之前在 Windows 这边用 Noptepad 改了配置文件,Linux 那边不认,还得用 nano 再改一遍。

    微软开发者明确标红:
    DO NOT, under ANY circumstances, access, create, and/or modify Linux files inside of your `%LOCALAPPDATA%` folder using Windows apps, tools, scripts, consoles, etc.
    详见 https://devblogs.microsoft.com/commandline/do-not-change-linux-files-using-windows-apps-and-tools/

    正确的姿势:
    升级到 Windows 10 version 1903 或更新版本
    在 WSL bash 中,运行`explorer.exe .`打开资源管理器,来访问 WSL 中的文件,文件路径如\$wsl\Ubuntu\etc\nginx\nginx.conf (暂不支持符号链接,已经反馈提议支持符号链接)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3058 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 159ms · UTC 14:12 · PVG 22:12 · LAX 07:12 · JFK 10:12
    ♥ Do have faith in what you're doing.