Summary of frequent WSL2 commands that I use.
Since WSL2 came to life, I have been very excited to use it and have been using it extensively. After connecting WSL2 to your favourite IDE in our earlier post. I wanted to summarize the most common commands I use and my experience with these commands as a cheat sheet that might come handy if you are new to it.
Note:
-
All these commands are in powershell or cmd unless specified otherwise.
-
I am running WSL2 on my Windows, with Windows 11 and Ubuntu 20.04.
The commands:
-
Starting up, either ‘wsl’ or start from startup menu type ubuntu.
-
To loggin and use WSL: in your powershell or CMD type.
-
WSL
-
Tip: to mount any folder to Ubuntu navigate to that folder and type wsl, then it will mount that path to Ubuntu directly.
-
-
To logout or exit WSL or Ubuntu, type:
- Exit
-
To list the virtual machines you have on your device, type in powershell or cmd:
-
WSL -l -v
-
-
For this command, it will also show the versions of WSL.
-
And it will show the status if it is on or off.
-
-
To get the status
- WSL – –status
-
For shutting down the virtual machine:
- Wsl – –shutdown
-
Setting working directory for Ubuntu:
-
Wsl – –cd Path:
- Path can be: ~ or / or c:\user\akram
-
Tip: if you navigate to a path in powershell or cmd then type WSL then ubuntu run and gets mounted to that path.
-
-
For other commands and help:
- Wsl -h or wsl – –help.
-
As all/most cmd commands, when a letter use ‘-’ and when a word use ‘– –’
-
To verify that your GPU is identified by Ubuntu run the command:
-
Nvidia-smi
-
You should see something like the following with your GPU name, I have Nvidia Quadro RTX 5000.
-
-
-
You can run commands to upgrade or downgrade your WSL if you need to. Check help for the commands.
-
Note:
-
Sometimes you will find a process named ‘vmmem ’
-
This is Windows cleaning processes/resources from the virtual machine so that might make your device busy. You want to make sure to shutdown your virtual machine when you do not need it.
-