# WSL使用

## wsl 命令行

选择安装 Linux 发行版

```sh
wsl --install
```

```sh
wsl --install -d Ubuntu
```

![wsl--install](https://static.qwas.fun/notes/2024/01/wsl--install.png)

 `wsl --status`查看 wsl 程序版本
 
 `wsl --update` 更新 wsl 程序

![wsl--status && wsl--update](https://static.qwas.fun/notes/2024/01/wsl--status-wsl--update.png)

`wsl --version` 查看 wsl 版本信息,较新版本 wsl 可用,旧版本没有这个命令参数

![wsl--version](https://static.qwas.fun/notes/2024/01/wsl--version.png)


`wsl --set-version 虚拟机名称 wsl版本号` 为虚拟机指定 WSL 版本

`wsl --set-version Ubuntu 2`

参看文档:[比较 WSL 版本 | Microsoft Learn](https://learn.microsoft.com/zh-cn/windows/wsl/compare-versions)

![wsl--version](https://static.qwas.fun/notes/2024/01/wsl--set-version.png)

## 磁盘管理

WSL 虚拟硬盘 (VHD) 的大小会随着使用而增加,设置稀疏磁盘后,系统会自动回收磁盘空间。

```sh
wsl --manage Ubuntu --set-sparse true
```

[有没有人用 wsl2 开发啊?文件系统爆炸磁盘待解救。 - V2EX](https://www.v2ex.com/t/996219)

```sh
diskpart  
select vdisk file="xxxx.vhdx"  
compact vdisk  
detach vdisk
```

Ubuntu 默认版本磁盘路径为

```text
C:\Users\dong\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState\ext4.vhdx
```

## 安装 zsh

```sh
sudo apt install zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
```
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9