Bring Your Favorite Linux Commands to Windows Command Prompt in Minutes!

Antony Oduor - Oct 31 - - Dev Community

an image displaying the results of running a linux command on a windows command prompt

If you live a double life where part of your day is spent on Linux and the other part on Windows, I’m about to make things a lot easier. Ever come home, open your Windows machine, type ls by reflex, only to see an error message? Don’t worry; you're not alone. With a small tool called BusyBox, you can bring familiar Linux commands like ls, pwd, and grep to Windows Command Prompt, no WSL or Cygwin needed. Here’s how to set it up quickly so you can switch between Windows and Linux environments with ease.

Why BusyBox?

BusyBox is a tiny, standalone executable that packages many Unix commands. Originally made for embedded systems, it combines dozens of commands into one lightweight program. You can think of it as a Swiss Army knife for Linux commands on Windows! With BusyBox, you get familiar commands without needing a complex setup.

Getting Started with BusyBox on Windows

Here’s a quick guide to set up BusyBox, allowing you to use commands like ls and grep in Windows Command Prompt just as you would in Linux.

Step 1: Download BusyBox

  1. Go to BusyBox for Windows and download the standalone executable.
  2. Place busybox.exe in a folder (for example, C:\busybox\). I like to keep all my custom tools under "C:\Program Files\" so I’d put it in C:\Program Files\busybox\.

Step 2: Add BusyBox to Your System Path

To make BusyBox accessible from any Command Prompt location, add it to your system’s PATH.

  1. Search for “Environment Variables” in the Windows Start menu and open Edit the system environment variables.
  2. In the System Properties window, click on Environment Variables….
  3. Under System variables, locate the Path variable, select it, and click Edit.
  4. Add the directory where you saved busybox.exe (like C:\Program Files\busybox\) and click OK.

To check if it worked, open a new Command Prompt and type busybox ls. If you see a directory listing, BusyBox is set up correctly! If not, double-check the PATH setup.

Step 3: Create Symlinks for Linux Commands

Right now, you’d need to prefix every command with busybox, as in busybox ls or busybox clear. But we can simplify things further by creating symbolic links (symlinks) so that typing ls or clear works as you’d expect. Here’s how:

  1. Open Command Prompt as Administrator. Search for "cmd," right-click, and select Run as administrator.
  2. Run these commands to create symlinks for frequently used commands:
   mklink "C:\Windows\System32\ls.exe" "C:\path\to\busybox.exe"
   mklink "C:\Windows\System32\pwd.exe" "C:\path\to\busybox.exe"
   mklink "C:\Windows\System32\grep.exe" "C:\path\to\busybox.exe"
   mklink "C:\Windows\System32\cat.exe" "C:\path\to\busybox.exe"
   mklink "C:\Windows\System32\clear.exe" "C:\path\to\busybox.exe"
   mklink "C:\Windows\System32\rm.exe" "C:\path\to\busybox.exe"
Enter fullscreen mode Exit fullscreen mode

Replace C:\path\to\busybox.exe with the actual path where you saved busybox.exe. For example, on my machine, I’d use:

   mklink "C:\Windows\System32\ls.exe" "C:\Program Files\busybox\busybox.exe"
Enter fullscreen mode Exit fullscreen mode

Each command above creates a symlink, meaning ls, pwd, grep, etc., will point to BusyBox automatically, no prefix needed.

Pro Tip: BusyBox has many commands available! To see a full list, type:

   busybox --help
Enter fullscreen mode Exit fullscreen mode

You can repeat the mklink command for any other commands you want to use directly.

Step 4: Test Your New Linux Commands

After setting up the symlinks, open a new Command Prompt window and try a few commands. Run ls, pwd, or grep just as you would on Linux. Here are a few examples:

ls
pwd
grep "text" file.txt
Enter fullscreen mode Exit fullscreen mode

If you see normal output without errors, congrats! You’ve just added Linux functionality to your Windows Command Prompt.

Optional: Automate with a Batch File

If you have many symlinks to create, save time by placing all mklink commands in a .cmd batch file. For example, create setup_busybox.cmd, add your commands, then run the file once to set up all symlinks at once. You can run .cmd files by simply writing their name(e.g: setup_busybox.cmd) on the command prompt then pressing the ENTER key.

Final Thoughts

By using BusyBox and symlinks, you can now run common Linux commands on Windows easily. No complex environments, just a lightweight tool and a few shortcuts. BusyBox covers most basic Linux commands, but if you need more specialized tools, consider options like Git Bash or WSL.

Give it a try and enjoy a unified command-line experience on Windows!

. . .