WSl2 (Windows Subsystem for Linux) essential commands.
Tags: wsl2, linux, tutorial, weeklyretro
Published: 2021-12-18 14:17:24

Many of us are using WSL or WSL2 because its hassle free and easy to setup and also fast. In this blog i will explain some basic commands of wsl to get you started.
## What is WSl?
Windows Subsystem for Linux is a compatibility layer for running Linux binary executables natively on Windows 10, Windows 11, and Windows Server 2019.

The Windows Subsystem for Linux lets developers run a GNU/Linux environment -- including most command-line tools, utilities, and applications -- directly on Windows, unmodified, without the overhead of a traditional virtual machine or dualboot setup which is pretty cool and hassle free.

## What is WSl2?
WSL 2 is a new version of the Windows Subsystem for Linux architecture that powers the Windows Subsystem for Linux to run ELF64 Linux binaries on Windows. Its primary goals are to increase file system performance, as well as adding full system call compatibility.

> The major difference between WSL and WSL2 is full support system call compatibility and increased file system performance.
According to Microsoft, WSL2 uses an actual full linux kernel running on a managed VM (virtual Machine) with fast boot times.

## To install wsl2 or wsl visit the link below.
[WSl/WSL2 install guide](https://docs.microsoft.com/en-us/windows/wsl/install)

## WSL commands.
Here are some wsl commands used mostly with explantions..

**1.**`wsl --install`
Install WSL and the Ubuntu distribution of Linux.

**2.** `wsl --install --distribution <Distribution Name>`
Install a specific Linux distribution besides the default (Ubuntu) by replacing <Distribution Name> with the name of the distribution. This command can also be entered as: wsl -d <Distribution Name>.

**3.** `wsl --list --online`
See a list of the Linux distributions available through the online store. This command can also be entered as: wsl -l -o.

**4.** `wsl --list --verbose`
See a list of the Linux distributions installed on your Windows machine, including the state (whether the distribution is running or stopped) and the version of WSL running the distribution (WSL 1 or WSL 2). 

**5.** `wsl --set-version <distribution name> <versionNumber>`
Set WSL version to 1 or 2.

**6.** `wsl --set-default-version <Version>`
To set a default version of WSL 1 or WSL 2, replacing <Version> with either the number 1 or 2 to represent which version of WSL you would like the installation to default on for new Linux distribution installations.

**7.** `wsl --set-default <Distribution Name>`
To set the default Linux distribution that WSL commands will use to run, replace <Distribution Name> with the name of your preferred Linux distribution.

**8.** `wsl ~`
To Change directory to home.

**9.** `wsl --distribution <Distribution Name> --user <User Name>`
Run a specific Linux distribution from PowerShell or CMD

**10.** `wsl --update`
Update Wsl

**11.** `wsl --status`
Check WSL status PowerShell

**12.** `wsl --help`
See a list of options and commands available with WSL.

**13** `wsl -u <Username>`, `wsl --user <Username>`
Run as a specific user

**14.** `<DistributionName> config --default-user <Username>`
Change the default user for a distribution

**15.** `wsl --shutdown`
To Shutdown/ Immediately terminates all running distributions and the WSL 2 lightweight utility virtual machine.

**16.wsl** `--terminate <Distribution Name>`
To terminate the specified distribution, or stop it from running, replace <Distribution Name> with the name of the targeted distribution.