Guide

How to run Linux commands on Windows

To run Linux commands on Windows, install the Windows Subsystem for Linux (WSL): open PowerShell as administrator, run wsl --install, and restart. You get a real Linux system, Ubuntu by default, with bash and the usual commands, running alongside Windows.

Below: the install, everyday wsl commands, running bash scripts on Windows, the Windows names for common Linux commands, and what to do when the Linux you need is on another machine.

  • One command to install
  • Bash scripts on Windows
  • Windows equivalents

Updated · Works on Windows 10 and 11

How to install WSL on Windows 11 and 10

WSL needs Windows 11, or Windows 10 version 2004 or later, and virtualization turned on in the PC's firmware (it usually is).

  1. Step 1: Run wsl --install

    Right-click Start, open Terminal (Admin) or Windows PowerShell (Admin), and run:

    wsl --install
  2. Step 2: Restart the PC

    Windows finishes turning on the features it needs when it starts again.

  3. Step 3: Create your Linux user

    Ubuntu opens by itself after the restart (or open Ubuntu from Start). Pick a user name and password. They're only for Linux and don't have to match your Windows ones; you'll type the password for sudo.

  4. Step 4: Update it

    sudo apt update && sudo apt upgrade

To pick another distribution, list them and install one by name:

wsl --list --online
wsl --install -d Debian

Everyday wsl commands

wsl                    # open a Linux shell in the current folder
wsl ls -la             # run one Linux command and come back to Windows
wsl -l -v              # installed distributions and their WSL version
wsl --update           # update WSL itself
wsl --shutdown         # stop every running distribution
  • Your Windows drives are inside Linux at /mnt/c, /mnt/d and so on.
  • Your Linux files show in File Explorer under Linux in the left pane, or at \\wsl.localhost\Ubuntu.
  • Linux tools are fastest on files kept in your Linux home folder rather than under /mnt/c.

How to run a bash script on Windows

With WSL installed, run the script from a Linux shell, or straight from Command Prompt or PowerShell:

chmod +x backup.sh
./backup.sh

wsl bash ./backup.sh     # from Command Prompt or PowerShell

"$'\r': command not found"?

The script was saved with Windows line endings. Convert it with sed -i 's/\r$//' backup.sh, and set your editor to save .sh files with LF (Unix) line endings.

For Windows' own scripting, see how to write and run a Windows batch script and remote PowerShell.

Linux commands and their Windows equivalents

Without WSL, Command Prompt has its own commands for the same jobs. PowerShell also accepts some Linux names, like ls, cat, cp, mv and rm, but their options differ. Windows 10 and 11 include ssh, scp, curl and tar as well.

Common Linux commands and the Command Prompt commands that do the same
JobLinuxCommand Prompt
List filesls -ladir
Show a filecat notes.txttype notes.txt
Search textgrep error log.txtfindstr error log.txt
Running programsps auxtasklist
End a programkill 4120taskkill /PID 4120
Network settingsip aipconfig
Copy, move, deletecp, mv, rmcopy, move, del
Clear the screenclearcls

When the Linux you need is on another machine

WSL is great for tools and scripts on your own PC. To work on a Linux server or another Linux PC, connect to it instead:

Questions, answered

Related