WSL Commands Cheat Sheet
WSL Commands Cheat Sheet
This cheat sheet provides essential commands for managing your Windows Subsystem for Linux (WSL) environment, covering backup, restore, symbolic links, and networking configurations. Mastering these commands will enhance your productivity and data management within WSL.
WSL Backup and Restore Commands
Efficiently back up your WSL distributions to prevent data loss and restore them when needed. These commands are crucial for system maintenance and migration.
Command | Description |
---|---|
wsl --list --verbose |
List all installed WSL distributions and their status (Running/Stopped). |
wsl --distribution <distro> |
Start or restart a specific WSL distribution. |
wsl --terminate <distro> |
Terminate a running WSL distribution. |
wsl --shutdown |
Terminate all running WSL distributions and the WSL process. |
wsl --export <distribution> <filename.tar> |
Export a WSL distribution to a tar archive for backup. |
wsl --import <distribution> <install location> <file location and filename> |
Import a WSL distribution from a tar archive, restoring it to a specified location. |
Managing WSL Symbolic Links
Create symbolic links to easily access Windows files and directories from within your WSL environment. This is particularly useful for sharing configurations like SSH keys and Kubernetes contexts.
Command | Description |
---|---|
sudo ln -s /mnt/c/Users/<user>/.ssh ~/.ssh |
Create a symbolic link for the .ssh folder from your Windows user profile to the WSL home directory. |
sudo ln -s /mnt/c/Users/<user>/.kube ~/.kube |
Create a symbolic link for the .kube folder from your Windows user profile to the WSL home directory. |
WSL Networking Configuration
Configure port forwarding and firewall rules to enable seamless network communication between your Windows host and WSL distributions, essential for running servers and services.
Command | Description |
---|---|
netsh interface portproxy add v4tov4 listenport=$port connectport=$port connectaddress=$remoteaddr |
Add a port forwarding rule to redirect traffic from a Windows port to a WSL IP address and port. |
netsh advfirewall firewall add rule name=$port dir=in action=allow protocol=TCP localport=$port |
Add an inbound firewall rule to allow TCP traffic on a specific local port. |
netsh interface portproxy delete v4tov4 listenport=$port |
Delete an existing port forwarding rule based on the listen port. |
netsh advfirewall firewall delete rule name=$port |
Delete an inbound firewall rule by its name. |
netsh interface portproxy show v4tov4 |
Display all configured IPv4 to IPv4 port forwarding rules. |
For more advanced networking configurations and troubleshooting, consult the official Microsoft documentation on WSL networking.
Explore further resources on Windows Subsystem for Linux to deepen your understanding and leverage its full potential for development workflows.
External Resources: