How to create ls in windows command prompt?

2019-01-16 02:06发布

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

How can I do that?

16条回答
劳资没心,怎么记你
2楼-- · 2019-01-16 02:42

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.

查看更多
在下西门庆
3楼-- · 2019-01-16 02:42

Its an old question but for the record:

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

Gives you ls and a whole lot more!

查看更多
疯言疯语
4楼-- · 2019-01-16 02:42

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.
查看更多
爷的心禁止访问
5楼-- · 2019-01-16 02:44

Surely ls would not work as a unix command for the batches. If you check %1 for -l or -a etc. and all combinations of them, it would work...

查看更多
在下西门庆
6楼-- · 2019-01-16 02:47

you could also use cygwin and just use the ls command directly along with all the other unix command line tools you might be used to.

查看更多
▲ chillily
7楼-- · 2019-01-16 02:49

I recommend the following recipe.

  1. Use DOSKEY and $* to create your ls command.
  2. Make the command persistent by recording it in a .bat/.cmd file and add the path of the file to registry.

For example, your command may look like
DOSKEY ls=dir
DOSKEY sublime="C:\Program Files\Sublime Text 2\sublime_text" $*
$* is useful for commands that take on arguments. For example, here I like to be able to do sublime my_code.c.

The registry for cmd is at HKEY_CURRENT_USER -> Software -> Microsoft -> Command Processor. Create a string valued entry called AutoRun with the full path of the file (not the containing folder) such as %USERPROFILE%\custom_command.cmd. Then each time cmd is run, your command will be loaded!

You can add more useful stuffs to the batch file too. See here for an example template.

查看更多
登录 后发表回答