Windows终端ubuntu如何改变起始目录

Windows terminal ubuntu how to change starting directory

我想知道如何将我的 windows 终端的起始目录从 /home/user/ 更改为 C:/Users/user。我尝试了一些我发现的东西,但没有任何效果。这是我在 settings.json 文件中指定的当前配置文件:

{
  "acrylicOpacity" : 1,
  "closeOnExit" : true,
  "colorScheme" : "One Half Dark",
  "commandline" : "ubuntu",
  "cursorColor" : "#FFFFFF",
  "cursorShape" : "bar",
  "fontFace" : "Consolas",
  "fontSize" : 10,
  "guid" : "{ba50f801-2d96-4517-a737-575f32f0fb61}",
  "historySize" : 9001,
  "icon" : "C:/Users/user/Pictures/ubuntu.png",
  "name" : "Ubuntu",
  "padding" : "0, 0, 0, 0",
  "snapOnInput" : true,
  "startingDirectory" : "C:\Users\user",
  "useAcrylic" : true
}

但是当我打开终端时,提示是 user@laptop:~$ 并且 pwd 给出 /home/user/

如果你的意思是wsl,你可以这样设置startingDirectory

"startingDirectory": "//wsl$/Ubuntu/home/user"

您可以在 Windows 资源管理器中探索路径 \wsl$

这对我有用(在 Windows 终端 1.0.1401.0、WSL2 和 Ubuntu 20.04 上):

"startingDirectory": "C:/Users/user"

问题是除了我创建的配置文件之外,还有一个自动生成的 ubuntu 配置文件。我开始使用自动生成的并删除了 "commandline" : "ubuntu" 选项,它现在监听 startingDirectory

对我来说,当我添加版本号时它起作用了://wsl$/Ubuntu-20.04/home/username

要更改 windows 终端的起始目录:

  • 打开windows终端设置

  • 转到 Ubuntu 个人资料页面并将“起始目录”更改为 \wsl$\Ubuntu\home\<user>

注意:我发布了另一个答案,因为它对我使用正斜杠不起作用