设置从Windows Terminal打开wsl时进入Linux用户主目录

当直接通过Windows Terminal的标题栏打开wsl时,默认会进入windows的用户目录,而这明显不属于Linux的目录结构,无法使用Linux的读写特性。

解决方法:

1. 确定commandline

在微软商店(Windows Store)中找到你当初安装的Linux发行版,从“简介->更多”中找一下启动命令。

例如:Ubuntu 是 ubuntu, Ubuntu18.04是 ubuntu1804, Ubuntu20.04是 ubuntu2004

Ubuntu
Ubuntu18.04

Ubuntu20.04

2. 打开配置文件

通过“设置”,打开Windows Terminal的配置文件

Windows Terminal

3. 添加commandline

在配置文件的profiles->list中找的你的Linux发行版,添加一行commandline:

"commandline": "ubuntu2004"

settings.json