如何从 WSL shell 的当前工作目录打开 Windows 资源管理器?

wes*_*ius 62 windows-subsystem-for-linux

当我在 Windows 资源管理器地址栏中键入“bash”并按 Enter 键时,它会在该目录中打开 shell。我经常发现自己想要在我通过 shell 到达的工作目录中使用 Windows 程序处理文件。有没有一种简单的方法可以从通过 shell 到达的位置打开资源管理器?

Sol*_*sei 85

在资源管理器中打开当前目录- 使用以下命令(WSL 自行设置 Windows 路径):

explorer.exe .
Run Code Online (Sandbox Code Playgroud)

您可以设置别名使用.bashrc自定义命令:

echo 'alias explorer="explorer.exe ."' >> ~/.bashrc
source ~/.bashrc
Run Code Online (Sandbox Code Playgroud)

现在只需使用:

explorer 
Run Code Online (Sandbox Code Playgroud)

在 Windows 资源管理器中打开当前工作目录。

  • 这将打开资源管理器到 C:\Windows\System32 文件夹。我错过了什么吗? (8认同)
  • @panta82,如果您在 linux 模拟目录中运行此命令,则 explorer.exe 无法解释它的路径,因此它会打开默认位置。但在未来的版本中,微软团队承诺将 linux 目录集成到 Windows 资源管理器中,因此可以开始工作。 (2认同)
  • 别名 explorer='explorer.exe `wslpath -w "$PWD"`' (2认同)

lav*_*rya 23

Microsoftwslpath正是为此目的提供了一个二进制文件。

explorer.exe `wslpath -w "$PWD"`
Run Code Online (Sandbox Code Playgroud)

从恶癖GitHub的问题,要求使用信息,有4个选项- ,,和。-a-u-w-m

wslpath usage:
    -a    force result to absolute path format
    -u    translate from a Windows path to a WSL path (default)
    -w    translate from a WSL path to a Windows path
    -m    translate from a WSL path to a Windows path, with ‘/’ instead of ‘\\’

    EX: wslpath ‘c:\users’
Run Code Online (Sandbox Code Playgroud)


tra*_*nag 17

您可以wslview像这样使用在 CWD 中打开资源管理器实例

wslview .
Run Code Online (Sandbox Code Playgroud)

它是wslutilities的一项功能,默认安装在较新的 Ubuntu WSL 发行版中。它可以安装在几乎所有其他流行的发行版中。

  • 被低估的答案 (5认同)
  • 这是WSL2的答案;接受的答案可能只适用于 WSL1。 (3认同)

Fra*_*ena 14

对于 WSL2,您可以像这样从 Windows 访问主目录:

\\wsl$
Run Code Online (Sandbox Code Playgroud)

很抱歉在聚会上迟到了!

  • 很好的提示,但它根本没有回答问题。 (3认同)

Koi*_*ima 5

我创建了一个名为eopen“轻松打开资源管理器”的小工具。 https://github.com/ko1nksm/eopen

Usage: eopen [options] [file | directory | uri]

options:
  -e, --editor      Open the file in text editor ($EOPEN_EDITOR)
  -n, --new         Open the specified directory in new instance of explorer
      --sudo        Use sudo to write the unowned file
  -v, --version     Display the version
  -h, --help        You're looking at it

note:
  The file or the directory allows linux and windows path.
  (e.g. /etc/hosts, C:/Windows/System32/drivers/etc/hosts)

  The uri must start with protocol schema. (e.g http:, https:)
Run Code Online (Sandbox Code Playgroud)

这是另一个解决方案。 https://github.com/4U6U57/wsl-open