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: 

  1. All these commands are in powershell or cmd unless specified otherwise.

  2. 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: