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 thedir
command only - add the directory where the
ls.bat
file exists to yourPATH
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:
- Install Git for Windows
- Add the
bin
directory of Git to your Path variable. Mine was located inC:\Program Files\Git\usr\bin
. - 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
Comments
-
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. over 12 years+1, I forgot to say that was windows xp but that is good for windows vista/7 :)
-
Pete Kirkham about 11 years+1
ls *
anddir *
don't do the same thing, so aliasing dir is a bit pants. -
MrHappyAsthma about 11 yearsI wish I could rate this more than once. Worked marvelously.
-
David 天宇 Wong about 11 yearswhy not put the ls.bat in system32 folder so you don't have to add the PATH
-
hmjd about 11 years@David天宇Wong, it is very possible that the user may not have write access to that folder.
-
nicorellius almost 11 yearsdoes this still work if you use it with args:
ls dir
? I think you would need to modify thels.bat
to handle args... or you could try aliases: superuser.com/questions/49170/create-an-alias-in-windows-xp -
ajon over 10 yearsThis is better because you can still use the dir options.
-
alexvetter over 10 yearsI recommend
echo dir %1 /B > %systemroot%\system32\ll.bat
for a simple list because I usell
more often thanls
. -
demented hedgehog about 10 yearsThis is the best answer. Ignore the voting and do this.
-
mrcrowl about 9 yearsI like: @echo off\ndir /w %1% to get closer to ls format
-
Aitor about 9 yearswork like a charm.. no more unrecognized command on windows! thank you!!
-
Adaline Simonian about 9 yearsI'd recommend using
dir %*
instead to allow for any number of command line arguments to be passed to dir through ls.bat. Otherwise, usingdir %1
, at most you can only use one argument when using the ls script. -
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 todir
-
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 over 8 yearsI've come back to this answer several times. Should definitely be on top.
-
DragonKnight over 8 yearswhen 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 over 8 yearsIt works for me in Windows10 (but you have to use a command line that has administrator privilege
-
david.barkhuizen over 8 yearswhile you're at it you may also want to add: echo cls %1 > %systemroot%\system32\clear.bat
-
War Gravy almost 8 yearsMarry me. This was the biggest life saver ever.
-
phil over 7 yearsGreat 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 over 7 yearsbest solution ever for linux user on windows,
npm install cash-global -g
. Would be great to addls -l
asll
(LL) also. -
jackD about 7 yearsIts a saviour mate
-
MadBoomy about 7 yearsexcellent answer, it shouldn't be possible to comment on this ;-)
-
Christopher Schneider almost 7 yearsA binary is unnecessary. Just use a symlink or bat file.
-
Johan over 6 yearsYes, or just start bash.exe in git folder (instead of cmd) and enjoy a ~complete shell (with ls).
-
omikes about 6 yearsdon't forget to add
C:\Program Files (x86)\GnuWin32\bin
to your path -
omikes about 6 yearsgit bash is hideous, i like the path option
-
information_interchange almost 6 yearsYou could also install cygwin and use the ls there :>
-
Danielr over 3 yearsPlease don't hack my facebook.
-
D4ITON over 2 yearsto use clear comand instead cls
echo cls > %systemroot%\system32\clear.bat