How to create ls in windows command prompt?

165,302

Solution 1

You could:

  • create a batch file called ls.bat and have it contain the dir command only
  • add the directory where the ls.bat file exists to your PATH environment variable

You could then execute ls from a command prompt.

Solution 2

You can solve this question with one simple command:

echo @dir %* > %systemroot%\system32\ls.bat

Make sure you run cmd.exe as admin first if you are on vista and up

Solution 3

Its an old question but for the record:

http://gnuwin32.sourceforge.net/packages/coreutils.htm

Gives you ls and a whole lot more!

Solution 4

Easiest way I have found is:

  1. Install Git for Windows
  2. Add the bin directory of Git to your Path variable. Mine was located in C:\Program Files\Git\usr\bin.
  3. Start a command prompt and enjoy ls in all its glory.

Solution 5

I have a solution but it's dirty:

Create a file named ls.bat containing only "dir".

Put it in C:\windows\system32 (or any directory in PATH env var).

That (should) works!

Edit: Something more consistent: https://superuser.com/questions/49170/create-an-alias-in-windows-xp

Share:
165,302
aF.
Author by

aF.

Last time I checked,                 I was me.

Updated on November 26, 2020

Comments

  • aF.
    aF. over 3 years

    I want to use ls in windows command prompt and make it run the dir command.

    How can I do that?

  • aF.
    aF. over 12 years
    +1, I forgot to say that was windows xp but that is good for windows vista/7 :)
  • Pete Kirkham
    Pete Kirkham about 11 years
    +1 ls * and dir * don't do the same thing, so aliasing dir is a bit pants.
  • MrHappyAsthma
    MrHappyAsthma about 11 years
    I wish I could rate this more than once. Worked marvelously.
  • David 天宇 Wong
    David 天宇 Wong about 11 years
    why not put the ls.bat in system32 folder so you don't have to add the PATH
  • hmjd
    hmjd about 11 years
    @David天宇Wong, it is very possible that the user may not have write access to that folder.
  • nicorellius
    nicorellius almost 11 years
    does this still work if you use it with args: ls dir ? I think you would need to modify the ls.bat to handle args... or you could try aliases: superuser.com/questions/49170/create-an-alias-in-windows-xp
  • ajon
    ajon over 10 years
    This is better because you can still use the dir options.
  • alexvetter
    alexvetter over 10 years
    I recommend echo dir %1 /B > %systemroot%\system32\ll.bat for a simple list because I use ll more often than ls.
  • demented hedgehog
    demented hedgehog about 10 years
    This is the best answer. Ignore the voting and do this.
  • mrcrowl
    mrcrowl about 9 years
    I like: @echo off\ndir /w %1% to get closer to ls format
  • Aitor
    Aitor about 9 years
    work like a charm.. no more unrecognized command on windows! thank you!!
  • Adaline Simonian
    Adaline Simonian about 9 years
    I'd recommend using dir %* instead to allow for any number of command line arguments to be passed to dir through ls.bat. Otherwise, using dir %1, at most you can only use one argument when using the ls script.
  • Captain Man
    Captain Man about 9 years
    @Vartan it's a shame that your comment is the first below the "show more" threshold. Hopefully @secghost will see this and modify their answer someday. I'd like to add that doing @dir %* will also remove the extra line so it is even more identical to dir
  • Adaline Simonian
    Adaline Simonian about 9 years
    @CaptainMan Oh, yeah! Totally forgot about @; nifty bit of syntax to use to avoid a mess of output. Though, it'd be so much easier if Windows was POSIX-compliant. At least we can dream.
  • Christopher Schneider
    Christopher Schneider over 8 years
    I've come back to this answer several times. Should definitely be on top.
  • DragonKnight
    DragonKnight over 8 years
    when i execute it it tells me access denied in windows 10. i gave write access to my user but yet didnt work. any idea?
  • Pierre Poliakoff
    Pierre Poliakoff over 8 years
    It works for me in Windows10 (but you have to use a command line that has administrator privilege
  • david.barkhuizen
    david.barkhuizen over 8 years
    while you're at it you may also want to add: echo cls %1 > %systemroot%\system32\clear.bat
  • War Gravy
    War Gravy almost 8 years
    Marry me. This was the biggest life saver ever.
  • phil
    phil over 7 years
    Great suggestion that gives access to full functionality of ls and all it's optional arguments. Just a slight update, I have installed the latest version of git for windows and the ls.exe can now be found in C:\Program Files\Git\ usr \bin
  • user2925656
    user2925656 over 7 years
    best solution ever for linux user on windows, npm install cash-global -g . Would be great to add ls -l as ll (LL) also.
  • jackD
    jackD about 7 years
    Its a saviour mate
  • MadBoomy
    MadBoomy about 7 years
    excellent answer, it shouldn't be possible to comment on this ;-)
  • Christopher Schneider
    Christopher Schneider almost 7 years
    A binary is unnecessary. Just use a symlink or bat file.
  • Johan
    Johan over 6 years
    Yes, or just start bash.exe in git folder (instead of cmd) and enjoy a ~complete shell (with ls).
  • omikes
    omikes about 6 years
    don't forget to add C:\Program Files (x86)\GnuWin32\bin to your path
  • omikes
    omikes about 6 years
    git bash is hideous, i like the path option
  • information_interchange
    information_interchange almost 6 years
    You could also install cygwin and use the ls there :>
  • Danielr
    Danielr over 3 years
    Please don't hack my facebook.
  • D4ITON
    D4ITON over 2 years
    to use clear comand instead cls echo cls > %systemroot%\system32\clear.bat