How To Use Bash On Windows

6 min read

Introduction

If you are a developer, system administrator, or simply a curious user who wants to run bash on a Windows machine, you are in the right place. In real terms, Bash is the GNU Bourne Again SHell, a powerful command‑line interpreter that originated on Unix‑like systems. By installing bash on Windows you gain access to a Unix‑style terminal, a rich set of command‑line tools, and the ability to script tasks that would otherwise require complex batch files. This article will walk you through everything you need to know to use bash on Windows, from preparing your system to mastering everyday commands.

You'll probably want to bookmark this section.

Prerequisites

Before you begin, make sure your Windows version meets the requirements:

  1. Windows 10 version 1607 or later (or Windows 11).
  2. Administrator rights on the machine, because the installation process modifies system components.
  3. An active internet connection, as the installation downloads several packages.

WSL (Windows Subsystem for Linux) is the official way Microsoft provides to run a Linux environment, including bash, directly on Windows. It is lightweight, integrates tightly with the file system, and does not require a virtual machine That alone is useful..

Installing Bash via WSL

1. Enable the WSL feature

Open PowerShell as Administrator and run:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

After the command completes, restart your computer. This step activates the core WSL component Worth keeping that in mind..

2. Install a Linux distribution

About the Mi —crosoft Store hosts several Linux distributions. The most popular choice for bash is Ubuntu, but you can also pick Debian, Kali Linux, or openSUSE. Follow these steps:

  1. Open the Microsoft Store from the Start menu.
  2. Search for “Ubuntu” (or your preferred distribution).
  3. Click Get and wait for the download and installation to finish.

When the installation is complete, launch the distribution from the Start menu. The first launch will ask you to create a UNIX username and password. Remember these credentials; they are used for sudo commands inside the Linux environment It's one of those things that adds up..

3. Set Bash as the default shell (optional)

By default, the distribution opens with the system’s default shell (often sh). To make bash the default, edit the user’s profile file:

nano ~/.profile

Add the line:

exec /usr/bin/bash --login

Save and exit (Ctrl+O, Enter, Ctrl+X). The next time you start the distribution, bash will launch automatically.

Using Bash on Windows

Accessing the Linux file system

WSL mounts the Linux file system under \\wsl$\<DistributionName>\ in Windows Explorer. For Ubuntu, you can access it via:

\\wsl$\Ubuntu\home\

This seamless integration lets you edit files with Windows tools (e.g., VS Code) while using bash commands to manipulate them Simple, but easy to overlook. But it adds up..

Basic command‑line workflow

  1. work through directories

    cd /home/yourusername/projects
    
  2. List files (the -l flag provides long format)

    ls -l
    
  3. Create a new file

    touch newfile.txt
    
  4. Run a command with elevated rights

    sudo apt update
    

Installing additional software

Inside the bash environment, you can install packages using the distribution’s package manager. For Ubuntu, the command is apt:

sudo apt install git curl htop

Each package you install becomes available in the bash shell, just like on a native Linux system.

Interoperability with Windows executables

You can call Windows executables directly from bash by specifying their full path, for example:

C:\Windows\System32\notepad.exe newfile.txt

Conversely, Linux commands can be launched from Windows using the wsl command:

wsl ls -l

Scientific Explanation

How WSL works under the hood

WSL leverages a lightweight virtualization layer that runs a genuine Linux kernel (since Windows 2022) or translates system calls on older versions. When you launch bash, the kernel spawns a user‑space process that interprets bash scripts, handles pipes, redirections, and job control exactly as it would on a native Linux machine. This design provides near‑native performance while allowing Windows applications to access the Linux environment through a mapped file system (\\wsl$\) Took long enough..

Why bash matters

Bash offers features absent from the traditional Windows cmd.exe or PowerShell pipelines, such as:

  • Arrays for storing lists of filenames.
  • Advanced pattern matching with [[ ]] and case statements.
  • Job control (&, ;, &&, ||) that lets you run multiple commands concurrently.

These capabilities make bash the preferred environment for many automation tasks, especially those that originated in Unix‑like ecosystems Simple, but easy to overlook. Nothing fancy..

Common Commands and Tips

  • pwd – Print working directory.
  • cd - – Switch back to the previous directory.
  • history – View previously executed commands; use !n to re‑run command number n.
  • man <command> – Access the manual page for any utility.
  • alias – Create shortcuts for long commands (add them to ~/.bashrc).

Useful one‑liners

# Find all .log files larger than 10 MB
find . -type f -name "*.log" -size +10M

# Display the top 5 memory‑hungry processes
ps aux --sort=-%mem | head -6

Troubleshooting

Symptom Likely Cause Fix
wsl command not recognized WSL not enabled or path not added Re‑run the `dism.
High CPU usage in WSL Too many background processes Stop unnecessary services (systemctl list-units --type=service) or limit resource usage via `.
Permission denied when using sudo Wrong username/password Verify the UNIX username and password you set during the first launch. In practice, exe` command, ensure the feature is enabled, then restart. Here's the thing —
File changes made in Windows not visible in Linux Using the wrong file system path Ensure you edit files under \\wsl$\<Distro>\ or use sudo to write to protected directories. wslconfig`.

Tweaking resource limits

Create a file named .wslconfig in your Windows user profile (`

C:\Users\<YourUsername>\.Here's the thing — wslconfig) to cap the amount of RAM and CPU cores the Linux kernel can consume. This prevents a runaway process in WSL from freezing your entire Windows host.

[wsl2]
memory=4GB    # Limits VM memory to 4 GB
processors=2  # Limits VM to 2 virtual processors

After saving the file, run wsl --shutdown in PowerShell to apply the new constraints.

Integration with Windows Tools

One of the most powerful aspects of WSL is its interoperability with the Windows ecosystem. You are not confined to a siloed environment; rather, you can bridge the two worlds without friction.

Interop Command Execution

You can execute Windows binaries directly from the bash prompt. Take this: if you want to open a file currently in your Linux directory using Notepad, you can simply run:

notepad.exe filename.txt

Similarly, you can call Windows-based tools like ipconfig.Consider this: exe or explorer. Day to day, exe . (the latter opens the current Linux directory in a Windows File Explorer window) to manage files visually.

The VS Code Advantage

For developers, the Remote - WSL extension for Visual Studio Code is indispensable. It allows VS Code to run its "server" component inside the Linux environment while the UI remains on Windows. This means you get the full power of Linux compilers, debuggers, and linters, but with the smooth, graphical interface of a native Windows application.

Conclusion

The marriage of Windows and Linux through WSL represents a paradigm shift in how developers and power users interact with their operating systems. Also, by providing a high-performance, genuine Linux kernel alongside the familiar Windows interface, Microsoft has eliminated the need for heavy, resource-intensive dual-boot setups or slow, clunky virtual machines. Think about it: whether you are automating complex file operations with bash one-liners, managing cloud-native containers, or performing deep scientific computing, WSL provides the speed, compatibility, and versatility required for modern technical workflows. Embracing this hybrid environment allows you to make use of the best of both worlds, making your development cycle faster and more efficient Worth knowing..

Just Went Live

New Today

Along the Same Lines

More to Chew On

Thank you for reading about How To Use Bash On Windows. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home