Table of Contents
In this article, we will see 11+ best wsl command examples on Windows 10 System. WSL or Windows Subsystem for Linux allows developers to run a GNU/Linux base environment with most of the general tools and applications already installed. This gives developers a hazzle free experience and saves lot of time creating a Virtual Machine or VM. WSL 1 is the currently widely available version but you can also use WSL 2 side by side reaping the benefits of using entirely new architecture. Here we will go through some of the best wsl command examples and understand its usage in real world scenario.
11+ Best WSL Command Examples on Windows 10 System
Also Read: Solved "You’re offline. Check your connection." YouTube Error
Example 1: How to List all Installed Distributions
If you are looking to check all the installed distributions then you need to use wsl -l -v
or wsl --list --verbose
command as shown below.
C:\>wsl -l -v NAME STATE VERSION * Ubuntu-20.04 Stopped 1
Example 2: How to Check the WSL Status
If you are looking to check information like default distribution, default version and other WSL configuration then you need to run wsl --status
command to check all those information.
C:\>wsl --status Default Distribution: Ubuntu-20.04 Default Version: 2 Please enable the Virtual Machine Platform Windows feature and ensure virtualization is enabled in the BIOS. For information please visit https://aka.ms/wsl2-install
Example 3: How to Shutdown a Distribution
If you are looking to shutdown a distribution then you need to use wsl --shutdown
command. For example, here we are shutting down Ubuntu-20.04
Linux distribution by using wsl --shutdown Ubuntu-20.04
command as shown below.
C:\>wsl --shutdown Ubuntu-20.04
You can then verify the distribution running status by using wsl -l -v
command as shown below.
C:\>wsl -l -v NAME STATE VERSION * Ubuntu-20.04 Stopped 1
Example 4: How to unregister a Linux Distribution
While you can install a linux distribution from Microsoft store, you can't uninstall it from there. To uninstall, you need to use wsl --unregister <DistributionName>
command. For example, to uninstall Ubuntu-20.04 linux distribution, you need to use wsl --unregister Ubuntu-20.04
command as shown below.
NOTE:
Microsoft Store
and then to Library
, you will still able to see the linux distribution. But if you click on open
again then instead of connecting it will start installing the distribution all over again.C:\>wsl --unregister Ubuntu-20.04 Unregistering. The operation completed successfully.
To check if the distribution is indeed uninstalled and deleted, you can run wsl -l -v
command as shown below.
C:\>wsl -l -v
Windows Subsystem for Linux has no installed distributions.
Use 'wsl.exe --list --online' to list available distributions
and 'wsl.exe --install <Distro>' to install.
Distributions can also be installed by visiting the Microsoft Store:
https://aka.ms/wslstore
Error code: Wsl/WSL_E_DEFAULT_DISTRO_NOT_FOUND
Example 5: How to Start a Linux Distribution
If you are having a linux distribution in stopped state, then you can start it again by using wsl -d <DistributionName>
command. For example, here we are starting a stopped Ubuntu 20.04 distribution by using wsl -d Ubuntu-20.04
command as shown below.
C:\>wsl -d Ubuntu-20.04
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
You will be logged in to the distribution. Then to logout, again you need to run exit
command as explained before.
cyberithub@DESKTOP-RS1VEHA:/mnt/c$ exit logout
Now if you check the distribution status using wsl -l -v
command then you will notice that the distribution is now in running state.
C:\>wsl -l -v NAME STATE VERSION * Ubuntu-20.04 Running 1
Example 6: How to Install a Distribution using wsl command
If you are looking to install a linux distribution then you need to use wsl --install -d <Distribution Name>
command. For example, if you need to install a Ubuntu
distribution then you need to use wsl --install -d Ubuntu
command as shown below. You can also install WSL by simply using wsl --install
command.
C:\>wsl --install -d Ubuntu
Example 7: How to List all online distributions
If you are looking to list all online distributions then you need to use wsl -l -o
or wsl --list --online
command as shown below.
C:\>wsl -l -o
Example 8: How to Export a Distribution using wsl command
If you are looking to export the linux distribution then you need to use wsl --export <distribution_name> <export_file>
command. In our case, we are exporting Ubuntu 20.04
distribution to the file ubuntu.tar
in the current location by using wsl --export Ubuntu-20.04 ubuntu.tar
command as shown below.
C:\>wsl --export Ubuntu-20.04 ubuntu.tar Export in progress, this may take a few minutes. The operation completed successfully.
Example 9: How to Import a Distribution
If you are looking to import a distribution then you need to use wsl --import <Distribution Name> <InstallLocation> <FileName>
command. In our case, we are importing ubuntu.tar
file to location D:\Ubuntu_distro
for new Ubuntu-20.04
distribution using wsl --import Ubuntu-20.04 D:\Ubuntu_distro ubuntu.tar
command as shown below.
C:\>wsl --import Ubuntu-20.04 D:\Ubuntu_distro ubuntu.tar Import in progress, this may take a few minutes.
Example 10: How to Update WSL to Latest Version
If you are looking to update WSL to the latest version then you need to use wsl --update
command as shown below.
C:\>wsl --update Installing: Windows Subsystem for Linux Windows Subsystem for Linux has been installed.
Example 11: How to Set default WSL Version
If you are looking to change the default WSL version then you need to use wsl --set-default-version <Version>
command. In this example, we are changing default WSL version to 1
by using wsl --set-default-version 1
command as shown below.
C:\>wsl --set-default-version 1 The operation completed successfully.
Example 12: How to Check all the available options
If you are looking to check all the options available with wsl command then you need to use wsl --help
command as shown below. More on official website.
C:\>wsl --help
Copyright (c) Microsoft Corporation. All rights reserved.
For privacy information about this product please visit https://aka.ms/privacy.
Usage: wsl.exe [Argument] [Options...] [CommandLine]
Arguments for running Linux binaries:
If no command line is provided, wsl.exe launches the default shell.
--exec, -e <CommandLine>
Execute the specified command without using the default Linux shell.
--shell-type <Type>
Execute the specified command with the provided shell type.
Types:
standard
Execute the specified command using the default Linux shell.
login
Execute the specified command using the default Linux shell as a login shell.
none
Execute the specified command without using the default Linux shell.
--
Pass the remaining command line as-is.
................................................................