WSL Cheat Sheet
Run a real Linux distro inside Windows. Run these commands from PowerShell or cmd. Inside the distro, use the Bash and apt sheets.
On this page
Install & Setup #
| Command | Action |
|---|---|
| Install WSL + Ubuntu (admin, then reboot) | |
| Install a specific distro | |
| List distros available online | |
| Update WSL itself | |
| Default distro and version | |
| WSL, kernel and WSLg versions |
Managing Distros #
| Command | Action |
|---|---|
| Installed distros, state and WSL version | |
| Start the default distro | |
| Start a specific distro | |
| Start in the Linux home folder | |
| Start as root (useful to reset a forgotten password) | |
| Change the default distro | |
| Convert to WSL 2 | |
| New installs use WSL 2 | |
| Stop one distro | |
| Stop everything (applies config changes) | |
| Delete a distro and all of its files |
Backup & Move #
| Command | Action |
|---|---|
| Back up a distro | |
| Restore / clone to another drive |
Files Between Windows and Linux #
| From | Path |
|---|---|
| Windows → Linux files | \\wsl$\Ubuntu\home\user or \\wsl.localhost\Ubuntu\... |
| Linux → Windows C: drive | /mnt/c/Users/you |
| Linux: open the folder in Explorer | |
| Linux: open in VS Code | (installs the WSL extension automatically) |
| Convert paths | → /mnt/c/Users (and for the reverse) |
Running Programs Across #
| Command | Action |
|---|---|
| Run a Linux command from PowerShell | |
| Run a Windows program from Linux | |
| / | Windows shell commands from Linux |
| Copy to the Windows clipboard from Linux |
Config Files #
/etc/wsl.conf (inside the distro):
[boot]
systemd=true
[user]
default=milan
[interop]
appendWindowsPath=true
%UserProfile%\.wslconfig (Windows, applies to all WSL 2 distros):
[wsl2]
memory=8GB
processors=4
swap=2GB
Run wsl --shutdown afterwards to apply.
Tips #
- Keep projects inside the Linux filesystem (
~/projects), not on/mnt/c. File access is much faster there. - Localhost is shared: a dev server on port 3000 in WSL opens at
http://localhost:3000in Windows. - GUI Linux apps work out of the box on Windows 11 (WSLg).
wslWindows Subsystem for Linux (run from PowerShell or cmd). wsl [options] [command]
| Option | What it does |
|---|---|
--install | Install WSL + Ubuntu (-d Debian for another distro, --no-launch) |
-l -v (--list --verbose) | Installed distros, state and WSL version |
-l -o (--list --online) | Distros you can install |
-d Ubuntu | Run a specific distro |
-u root | Run as another user |
-e cmd / wsl cmd | Run one Linux command: wsl ls -la |
--cd C:\dev / wsl ~ | Start folder / start in the Linux home folder |
-s Ubuntu (--set-default) | Default distro |
--set-version Ubuntu 2 | Convert a distro to WSL 2 |
--set-default-version 2 | WSL version for new installs |
-t Ubuntu (--terminate) | Stop one distro |
--shutdown | Stop everything (applies .wslconfig changes) |
--unregister Ubuntu | ⚠ Delete a distro and all its files |
--export Ubuntu file.tar | Back up a distro |
--import Name C:\WSL\Name file.tar | Restore / clone a distro |
--update | Update WSL |
--status / --version | Default distro / version numbers |
--mount \\.\PHYSICALDRIVE1 | Mount a physical disk in WSL 2 |
explorerOpen File Explorer. explorer [folder | /select,file | shell:folder]
| Usage | What it does |
|---|---|
explorer . | Open the current folder |
explorer /select,"C:\path\file.txt" | Open the folder and select the file |
explorer shell:startup | Special folders: shell:downloads, shell:appsfolder, shell:sendto |
explorer https://example.com | Open a URL in the default browser |
explorer.exe . | From WSL: open the Linux folder in Explorer |
codeVS Code from the command line. code [options] [paths…]
| Option | What it does |
|---|---|
code . | Open the current folder |
-r, --reuse-window | Open in the last active window |
-n, --new-window | Open in a new window |
-g file:line[:col] | Go to a line: code -g app.js:42 |
-d a b, --diff | Compare two files |
-m a b base result | Three-way merge |
-a folder | Add a folder to the current window |
-w, --wait | Wait until the file is closed (Git editor: code --wait) |
--install-extension id | Install an extension (--uninstall-extension to remove) |
--list-extensions | Installed extensions (--show-versions for versions) |
--profile "Name" | Open with a profile |
--disable-extensions | Start without extensions (troubleshooting) |
-v | Version |
wslpathConvert paths between Windows and WSL (run inside WSL). wslpath [option] path
| Option | What it does |
|---|---|
wslpath 'C:\Users\milan' | Windows → Linux: /mnt/c/Users/milan (-u is the default) |
-w /home/milan | Linux → Windows: \\wsl.localhost\Ubuntu\home\milan |
-m /home/milan | Windows path with forward slashes |
-a | Force an absolute path |
notepadOpen Notepad. notepad [file]
| Usage | What it does |
|---|---|
notepad file.txt | Open (or create) a file |
notepad | Empty Notepad |
notepad /p file.txt | Print the file |
From WSL use notepad.exe file.txt.
cmdStart the Command Prompt, or run one cmd command. cmd [options]
| Option | What it does |
|---|---|
/c "dir" | Run a command and close (cmd //c "dir" in Git Bash) |
/k "echo hi" | Run a command and stay open |
/q | Turn off command echo |
/s | Strip the outer quotes of the command |
/v:on | Delayed variable expansion (!var!) |
/u | Output Unicode to files and pipes |
/e:on | Command extensions (default on) |
powershellalso: pwshStart PowerShell (5.1 = powershell, 7+ = pwsh), for example from cmd or a script.
| Option | What it does |
|---|---|
-Command "Get-Date" (-c) | Run a command and exit |
-File script.ps1 | Run a script file |
-NoProfile | Don't load your profile (faster, predictable) |
-ExecutionPolicy Bypass | Ignore the script policy for this run |
-NoExit | Stay open after running the command |
-NoLogo | Hide the banner |
-NonInteractive | Never prompt (automation) |
-WindowStyle Hidden | Run without a visible window |
-EncodedCommand … | Run a Base64-encoded command |
-WorkingDirectory C:\dev | Start folder (pwsh only) |
-Version | Show the version (pwsh only) |
echoPrint text. echo [options] text…
| Option | What it does |
|---|---|
-n | No newline at the end |
-e | Interpret escapes: \n newline, \t tab |
-E | Don't interpret escapes (default) |
echo $HOME | Print a variable |
echo "text" > file | Write to a file (>> appends) |
echo $? | Exit code of the last command |
Nothing on this sheet matches “”.