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).
Step 1: Run wsl --install
Right-click Start, open Terminal (Admin) or Windows PowerShell (Admin), and run:
wsl --install
Step 2: Restart the PC
Windows finishes turning on the features it needs when it starts again.
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.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"?
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.
| Job | Linux | Command Prompt |
|---|---|---|
| List files | ls -la | dir |
| Show a file | cat notes.txt | type notes.txt |
| Search text | grep error log.txt | findstr error log.txt |
| Running programs | ps aux | tasklist |
| End a program | kill 4120 | taskkill /PID 4120 |
| Network settings | ip a | ipconfig |
| Copy, move, delete | cp, mv, rm | copy, move, del |
| Clear the screen | clear | cls |
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:
- SSH:
ssh user@serverfrom PowerShell, or save the server in the RemoteAccessApp app and open it in a tab with SFTP next to it. See how to SSH into a Linux server from Windows. - A Linux PC with RemoteAccessApp on it: open a terminal on it from your Windows PC, without a session or an SSH server. See a Linux terminal without a remote session.
- The whole Linux desktop: control a Linux PC from Windows.
Questions, answered
Related
- Windows batch scriptsCreate and run a .bat or .cmd file, the batch commands you'll use most, an example, and running a script on many PCs at once.Read the guide
- SSH to a Linux serverConnect to a Linux server from Windows or another Linux machine, check its key, and copy files.Read the guide
- Linux terminal without a sessionRun a command or open a bash terminal on a Linux PC from the Devices page: straight away under unattended access, otherwise after an Allow.Read the guide
- Control Linux from WindowsYour Linux PCs on the Console's Devices page next to your Windows PCs: screen and control, a bash terminal, processes, services and the journal.Read the guide
- Remote PowerShellEnable-PSRemoting, Enter-PSSession and Invoke-Command for PCs with no domain, enabling Remote Desktop from PowerShell or cmd, and a way with no setup.Read the guide
- SSH & SFTP clientTerminal tabs, an SFTP and FTP file manager, key sign-in and one command to every server.Learn more
