如何从 Ubuntu 路径中删除 Windows 路径?

如何从 Ubuntu 路径中删除 Windows 路径?

如何从 Ubuntu 路径中删除 Windows 路径?

~/.bashrc 或其他文件不包含它。

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss = "AppendNtPath"=dword:00000000
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss{....} = "AppendNtPath"=dword:00000000

它没有效果。

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss{GUID}\Flags

将标志从 7 更改为 5,已重置我的 Ubuntu,消除了我拥有的所有内容。

答案1

如果你想阻止 WSL 附加全部将 Windows PATH 元素添加到 Linux 路径,创建(或编辑)/etc/wsl.conf以下内容:

[interop]
appendWindowsPath=false

然后退出 WSL,从 PowerShell 或 CMD 执行wsl --shutdown,然后重新启动。

也就是说,这将使许多有用的功能在 WSL 中更难使用,因为您必须使用其完整路径来调用 Windows 命令。至少考虑在 shell 启动中手动添加某些命令,例如:

  • /mnt/c/Windows/System32
  • /mnt/c/Windows
  • /mnt/c/Windows/System32/WindowsPowerShell/v1.0/
  • 如果你安装了 VSCode,其路径
  • 如果你安装了 PowerShell Core,其路径

答案2

如果你只想暂时的删除 Windows PATH,您可以使用以下命令:

export PATH=$(echo $PATH | tr ":" "\n" | grep -v "/mnt/c" | paste -sd ":")

它将过滤当前的$PATH,删除以 开头的所有条目/mnt/c,保留其他所有内容,并将其设置为新的$PATH

答案3

解决覆盖路径的问题

~/.profile 导出 PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

相关内容