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:
- Find the
usr\binsubfolder of the git installation folder (by default, it will beC:\Program Files\Git\usr\bin). If you installed git somewhere else, find theusr\bindirectory inside that other location. - Open
This PCorComputer, right click in the directory and selectProperties. Control Panel > System and Security > System window will open. - On the left, choose
Advanced system settingsand clickEnvironment Variablesat the bottom.
- In the
Environment Variableswindow, findPathvariable in theSystem Variableson the bottom part of the screen. - Click
Editand add path to theuser\binsubdirectory of git installation folder in there:- If git is installed in
C:\Program Files\Git - Path to add is:
C:\Program Files\Git\usr\bin
- If git is installed in
- Click
OK, thenOK, thenOKand then open the new command line. Running thelscommand now will result in listing the items of a current working directory.
Common issues
-
I can't find my git installation folder, how do I look it up? If you can run the
gitcommand from commandline:- Go to
This PC, right click and selectProperties - Select
Advanced system settingson the left - Select
Environment Variableson the bottom and look for anything with agitin the path. There you will eventually find the actual git installation directory.
- Go to
-
I followed the tutorial and still can't use
lsin my CMD, what should I do? Start a new commandline window:- Either press
Windows Key+Rand type in CMD, or just find it in the start menu. - Run
lsagain 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.
- Either press
Top comments (0)