Essential WSL Commands


The Windows Subsystem for Linux (WSL) is a game-changer for anyone who needs the power of Linux but prefers the familiarity of Windows. By enabling you to run a full Linux environment directly within Windows, WSL simplifies workflows for developers, system administrators, and Linux enthusiasts alike.
In this post, we’ll explore some of the most practical WSL commands, offering you a cheat sheet for managing your WSL setup. Whether you’re just starting out or looking to enhance your efficiency, this guide has you covered.
Simply put, WSL allows you to run Linux on Windows without the need for virtual machines or dual-boot setups. It’s a seamless experience that lets you tap into Linux tools while staying in the comfort of your Windows workspace.
Think of it as a bridge connecting the best of both worlds: Linux's flexibility and Windows’ accessibility.
Here’s a breakdown of commands that every WSL user should keep handy.
If you’ve installed multiple Linux distributions in WSL, you’ll likely want to set a default one. This ensures that whenever you run wsl in the terminal, the specified distribution is launched.
Command:
wsl --set-default <DistributionName>Example:
wsl --set-default UbuntuYou can check your installed distributions with:
wsl --list --verboseThis is particularly useful if you use different distributions for different tasks.
By default, WSL might log you in as the root user, but you can easily change that.
Command:
<DistributionName> config --default-user <username>Example:
ubuntu config --default-user developerThis ensures you log in as developer by default, saving you the extra step of switching users manually.
Sometimes, you might want to stop all running WSL instances—perhaps to save system resources or troubleshoot an issue. The shutdown command is your go-to in such cases.
Command:
wsl --shutdownThis gracefully stops all running distributions and closes any active WSL processes.
Each WSL instance operates on a virtual network with its own IP address. Knowing this can be helpful, especially when you’re setting up services or accessing your WSL environment remotely.
From within WSL:
ip addr show eth0From Windows (Command Prompt or PowerShell):
wsl hostname -IThe output will display the IP address of your WSL instance.
Want to work with a specific Linux distribution without setting it as the default? You can launch it directly:
Command:
wsl -d <DistributionName>Example:
wsl -d DebianThis flexibility lets you switch between distributions effortlessly.
Backing up your work or moving WSL instances between machines is straightforward with the export and import commands.
To export a distribution:
wsl --export <DistributionName> <FileName.tar>To import it back:
wsl --import <NewDistributionName> <InstallLocation> <FileName.tar>Example:
wsl --export Ubuntu ubuntu_backup.tar
wsl --import RestoredUbuntu C:\WSL\RestoredUbuntu ubuntu_backup.tarThis method ensures you can recreate your WSL setup anywhere with minimal effort.
WSL supports both version 1 and version 2. You can check which version your distributions are using with:
wsl --list --verboseTo change the version of a distribution, use:
wsl --set-version <DistributionName> <VersionNumber>Example:
wsl --set-version Ubuntu 2Microsoft frequently releases updates to improve WSL’s performance and compatibility. To stay up to date:
wsl --updateThis ensures you’re always running the latest version.
One of WSL’s strengths is its seamless integration with the Windows file system. You can access Linux files from Windows by navigating to:
\\wsl$\<DistributionName>From the Linux side, you can access Windows files via:
/mnt/<DriveLetter>Example:
cd /mnt/cThis convenience makes it easy to work across platforms.
If you no longer need a specific Linux distribution, you can unregister it to free up space:
Command:
wsl --unregister <DistributionName>Example:
wsl --unregister UbuntuNote: This action is irreversible, so proceed with caution!

Stop fighting Git permissions in WSL. This post explains the root cause of the 'Permission Denied' error and shows you the permanent fix.

Get the essential commands to quickly find where your WSL distributions are stored and how to import them from a VHDX file

Follow this easy tutorial to set up Ubuntu on Windows with WSL. Install, configure, and explore the Linux file system.