在Windows的特定或当前文件夹中启动WSL Ubuntu

Bas*_*mme 13 windows windows-subsystem-for-linux

从他的开发机上的商店中安装Linux和Ubuntu的Subsystem时,我可以简单地切换(或启动)到Ubuntu shell

在此处输入图片说明

但是,Ubuntu Shell /home/techsupp默认情况下从文件夹启动。是否可以强制它与我使用的Ubuntu命令在同一文件夹中启动?

所以在我的例子中,我应该在

/mnt/h
Run Code Online (Sandbox Code Playgroud)

谢谢。

我已经尝试过的

H:\>ubuntu help
Launches or configures a linux distribution.

Usage:
    <no args>
      - Launches the distro's default behavior. By default, this launches your default shell.

    run <command line>
      - Run the given command line in that distro, using the default configuration.
      - Everything after `run ` is passed to the linux LaunchProcess call.

    config [setting [value]]
      - Configure certain settings for this distro.
      - Settings are any of the following (by default)
        - `--default-user <username>`: Set the default user for this distro to <username>

    clean
      - Uninstalls the distro. The appx remains on your machine. This can be
        useful for "factory resetting" your instance. This removes the linux
        filesystem from the disk, but not the app from your PC, so you don't
        need to redownload the entire tar.gz again.

    help
      - Print this usage message.
Run Code Online (Sandbox Code Playgroud)

我还在uservoice上发现了此请求:https ://wpdev.uservoice.com/forums/266908-command-prompt-console-windows-subsystem-for-l/suggestions/13421103-let-us-right-click-open- bash从这里浏览器?tracking_code = 8a8bc624c72a8336565fcd6d5737d712

请投票。

Emm*_*rra 57

我在带有 May Update 的 Windows 10 Home 上安装了用于 WSL 的 Ubunto 18.04,我可以使用Shift + 右键单击并选择在此处打开 Linux shell选项在任何文件夹中打开控制台

在此处输入图片说明

  • 如果有帮助,我创建了一个可以运行的注册表文件,通过 **右键单击** 来执行此操作,而不是 **Shift + 右键单击​​*。如果您按照顶部的说明进行操作,它还会在上下文菜单中显示 Ubuntu 图标。https://gist.github.com/Zantier/692fd3e1a28d54708e95921de9b27e67 (2认同)
  • 这对我来说不太有效。(见@刘回答)。如果您安装了两个或多个发行版(例如 Ubuntu 和 Fedora),则将启动默认发行版。您可以通过运行 wslconfig /setdefault Ubuntu 将默认值设置为 Ubuntu。显然我默认使用 Fedora,并且我的所有命令(我只在 Ubuntu 中安装)都不起作用:( (2认同)
  • 这不再适用于 WSL2 (2认同)

tal*_*les 25

如果您在任务管理器中检查资源管理器“在此处打开 Linux shell”选项如何打开 wsl,您可以看到有一个“--cd”选项。

  • 很好的答案和很棒的发现!基于此,还请注意,您可以通过 `wsl.exe --cd "\\wsl$\&lt;distroName&gt;"` 在 WSL 路径中启动(将以 `/` 启动)。我只是希望 `--cd` 选项记录在 `wsl --help` 中。 (3认同)
  • @NotTheDr01ds 实际上记录了“--”选项,请参阅“wsl --help”:“-- 按原样传递剩余的命令行。” (3认同)
  • @klapshin我想也许你看到了我没有放置的换行符或空格;-)。我知道“--”已记录在案。我说我希望“--cd”被记录下来。`--cd` 是 wsl 命令的实际*标志*,而不是作为 `--` 的结果传递的 `cd` 命令(如果是这样,则后面需要一个空格)。 (2认同)
  • @klapshin 不用担心。您是正确的,“--cd”(带有空格)会将“cd”命令传递到 wsl 会话中,但结果是它将“cd”,然后立即退出,因为这将是发送的唯一命令到外壳。 (2认同)

X. *_*Liu 13

如果使用wsl.exe,它将在当前目录中启动 WSL。但之间的区别wsl,并ubuntu是,如果你已经安装了两个或两个以上的发行版(E,G,Ubuntu和Fedora的),默认的将上手。您可以通过运行将默认设置为 Ubuntu wslconfig /setdefault Ubuntu

参考:[1] https://docs.microsoft.com/en-us/windows/wsl/wsl-config


Mar*_*ang 9

似乎有一个非常简单的解决方案。

只需在profiles.json文件中的Ubuntu配置中添加以下内容

"命令行": "wsl ~ -d Ubuntu",


bol*_*lov 7

ubuntu run
Run Code Online (Sandbox Code Playgroud)

运行<command line>
   在当前工作目录中运行提供的命令行。如果未
   提供命令行,则将启动默认外壳程序。

据我所知,效果与运行相同ubuntu,除了它从当前目录开始。

即使在资源管理器中右键单击“在此处打开”命令,此命令也可以工作。根据本文改编:

  • RegEdit HKEY_CLASSES_ROOT\Directory\Background\shell并创建一个新密钥
  • 编辑(Default)为“在此处打开Ubuntu”或类似内容。
  • 添加一个名为 command
  • 编辑(Default)ubuntu run

现在,您可以在资源管理器中右键单击菜单“在此处打开Ubuntu”。


wsl遇到的问题是,即使wsl bash窗口启动了Ubuntu发行版,它也没有Ubuntu图标。


Shr*_*hak 6

第 1 步:安装Windows 终端

步骤 2:转到要在其中打开 Ubuntu 的文件夹,然后右键单击打开 Windows 终端。

步骤 3:转到 Windows 终端设置并导航到您的 Linux 发行版(在我的例子中为 Ubuntu 20.04)并选中此选项。

在此输入图像描述

现在,每次您通过 Windows 终端打开 Ubuntu 时,它都会在该目录中打开。


Jub*_*ott 5

对我有用的方法是使用 Windows 终端应用程序并将其配置为在所需位置启动。

基于 WSL2 和 Ubuntu 20.04 的示例:

settings.json - 将此行添加到“Ubuntu-20.04”部分:

    "startingDirectory": "//wsl$/Ubuntu-20.04/home/<username>/"
Run Code Online (Sandbox Code Playgroud)

将 <username> 更改为您在安装 Ubuntu 20.04 时创建的用户名。