How to add ls and other Linux commands into Windows commandline

2022-12-25 | Tutorials

Whenever I happen to be using the command line on Windows, I always end up running ls command and getting the annoying error 'ls' is not recognized as an internal or external command, operable program or batch file. This command is sometimes available in powershell, but never by default in cmd. Turns out there is an easy way to make it available, and in this post I will explain how.

The trick relies on git being installed on Windows system already. My assumption here is that you, the reader, is someone who works in tech and therefore chances are, you already have git on your machine. If that is not the case, you can install git by following this guide.

TL;DR - what's the trick - git is a tool that allows you to manage versions of your code projects and happens to bring the Windows executables for a lot of linux commands with the installation. You can add the directory where these executables are stored into the path and make them available in the CMD. Steps how to achieve this are bellow:

Image of System and Security / System in Control Panel, Advanced system settings option in the left menu is highlighted)

Common issues

  1. I can't find my git installation folder, how do I look it up? If you can run the git command from commandline:
    • Go to This PC, right click and select Properties
    • Select Advanced system settings on the left
    • Select Environment Variables on the bottom and look for anything with a git in the path. There you will eventually find the actual git installation directory.
  2. I followed the tutorial and still can't use ls in my CMD, what should I do? Start a new commandline window:
    • Either press Windows Key + R and type in CMD, or just find it in the start menu.
    • Run ls again and it should work now.
    • Why? You were probably trying to run the command from previously opened CMD, which read the old value of Path variable when it was starting. It doesn't know about the changes you have made into the path yet.