# Basic WSL Commands


> Run these commands in PowerShell or in the windows command line. 


- Run Linux commands from the Windows command line.

```Markdown

wsl ls -alh
# this will run the ls command in the current directory.

wsl sudo apt update
# this updates the package lists for upgrades 
# for packages that need upgrading.

```

- Mix Linux and Windows commands 

``` Markdown

wsl ls -la | findstr "hello"
# this will use the ls command to list the contents of a dir 
# and then pipe the output to the findstr command in windows.

dir | wsl grep "hello"

```

- Open Windows software from Linux

```Markdown

notepad.exe
# this will open notepad

notepad.exe "C:\folder\hello.txt"
# open a file in notepad

explorer.exe .
# this will open the explorer in the current directory.

```

- Launch WSL from the windows command line

```Markdown

wsl 
# or
wsl.exe
# this will open WSL inside the current directory

exit 
# this will close WSL

```

- List installed distributions 

```Markdown

wsl --list
# this will list all the installed distributions

wsl --list --running
# this will list all the running distributions 

```

- Set a default distribution

```Markdown

wsl -s <DistributionName>, wsl --setdefault <DistributionName>

# exmaple 
# wsl -s Ubuntu

```

- Unregister and reinstall a distribution

Unregister means uninstall here. 
<br>
While the distribution can be installed from the store it can not be uninstalled from the store.

```Markdown

wsl --unregister <DistributionName>

```

To reinstall, find the distribution in the Microsoft store and select "Launch".

- Set WSL 2 as your default version

```Markdown

wsl --set-default-version 2

```

- Know which distribution is running what version of WSL

```Markdown

wsl --list --verbose

```

- Set your distribution to use WSL 1 or WSL 2

```Markdown

wsl --set-version <distribution name> <versionNumber>

# example
# wsl --set-version Ubuntu 2

```

- WSL 2 your default architecture

```Markdown

wsl --set-default-version 2

```

