Distributions
wsl --list --verbose
List distros with state and version
Short form: wsl -l -v. The * marks the default.
wsl --list --running
List running distros only
wsl --set-default <distro>
Make a distro the default
Short form: wsl -s <distro>.
wsl --terminate <distro>
Stop one distro
Short form: wsl -t <distro>.
wsl --shutdown
Stop all distros and the VM
Needed after editing .wslconfig or wsl.conf.
wsl --set-version <distro> 2
Convert a distro to WSL 2
Can take long and fail on big distros: export a backup first.
wsl --set-default-version 2
Use WSL 2 for new installs
wsl --unregister <distro>
Remove a distro and ALL its data
Deletes the root filesystem permanently; there is no undo.
wsl --manage <distro> --set-default-user
<user>
Change the login user
The user must already exist in the distro.
wsl --manage <distro> --move <dir>
Move the distro's disk
Run Linux from Windows
wsl
Shell in the default distro
Starts in the current Windows directory.
wsl ~
Shell in your Linux home
wsl -d <distro>
Shell in a specific distro
wsl -u root
Shell as root
Forgot the sudo password? Reset it here with passwd
<user>.
wsl <command>
Run one Linux command
Uses the current directory; paths must be Linux paths.
wsl --cd <dir>
Start in a given directory
~ = Linux home, /path = Linux path, else a Windows path.
dir | wsl grep <text>
Pipe Windows output into Linux tools
Backup and disks
wsl --export <distro> <file.tar>
Back up a distro to a tar file
Use - as the file name to write to stdout.
wsl --import <name> <dir>
<file.tar>
Restore or clone as a new distro
No launcher for imports: set the user via [user] default.
wsl --manage <distro> --compact
Compact the distro's VHDX
wsl --mount <disk>
Mount a disk in WSL 2
Admin prompt. Add --vhd for a .vhdx, --bare to attach only.
wsl --unmount <disk>
Detach a disk (all if omitted)
Networking
localhost:<port>
Reach a Linux server from Windows
Works by default (localhostForwarding).
wsl hostname -I
IP address of the WSL 2 VM
Capital -I; lower-case -i prints a placeholder address.
ip route show | grep -i default | awk '{print
$3}'
Windows host IP, seen from Linux
Only needed in NAT mode.
[wsl2] networkingMode=mirrored
Share Windows' network interfaces
Windows 11 22H2+. Adds IPv6, LAN access and localhost both
ways.