Essential WSL Commands

wsl essential command

Top 10 WSL Commands to Maximize Productivity on Windows

WSL
WSL troubleshooting
Linux on Windows
Windows Subsystem for Linux
WSL export import
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.


What is WSL, and Why Should You Care?

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.


10 Must-Know Commands for Managing WSL

Here’s a breakdown of commands that every WSL user should keep handy.


1. Setting the Default Linux Distribution

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 Ubuntu

You can check your installed distributions with:

wsl --list --verbose

This is particularly useful if you use different distributions for different tasks.


2. Switching the Default User

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 developer

This ensures you log in as developer by default, saving you the extra step of switching users manually.


3. Shutting Down WSL

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 --shutdown

This gracefully stops all running distributions and closes any active WSL processes.


4. Finding Your WSL IP Address

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 eth0

From Windows (Command Prompt or PowerShell):

wsl hostname -I

The output will display the IP address of your WSL instance.


5. Starting a Specific Distribution

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 Debian

This flexibility lets you switch between distributions effortlessly.


6. Exporting and Importing Distributions

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.tar

This method ensures you can recreate your WSL setup anywhere with minimal effort.


7. Checking or Changing the WSL Version

WSL supports both version 1 and version 2. You can check which version your distributions are using with:

wsl --list --verbose

To change the version of a distribution, use:

wsl --set-version <DistributionName> <VersionNumber>

Example:

wsl --set-version Ubuntu 2

8. Keeping WSL Updated

Microsoft frequently releases updates to improve WSL’s performance and compatibility. To stay up to date:

wsl --update

This ensures you’re always running the latest version.


9. Navigating Files Between Windows and WSL

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/c

This convenience makes it easy to work across platforms.


10. Removing a Distribution

If you no longer need a specific Linux distribution, you can unregister it to free up space:

Command:

wsl --unregister <DistributionName>

Example:

wsl --unregister Ubuntu

Note: This action is irreversible, so proceed with caution!