如何在 Windows 命令提示符下创建 ls?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9362692/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 09:15:29  来源:igfitidea点击:

How to create ls in windows command prompt?

windowswindows-xpcmdlsdir

提问by aF.

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

我想在 Windows 命令提示符中使用 ls 并使其运行 dir 命令。

How can I do that?

我怎样才能做到这一点?

回答by secghost

You can solve this question with one simple command:

你可以用一个简单的命令来解决这个问题:

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

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

cmd.exe如果您使用的是 vista 或更高版本,请确保首先以管理员身份运行

回答by hmjd

You could:

你可以:

  • create a batch file called ls.batand have it contain the dircommand only
  • add the directory where the ls.batfile exists to your PATHenvironment variable
  • 创建一个批处理文件ls.bat并让它dir只包含命令
  • ls.bat文件所在的目录添加到您的PATH环境变量中

You could then execute lsfrom a command prompt.

然后您可以ls从命令提示符执行。

回答by sipi

Its an old question but for the record:

这是一个古老的问题,但为了记录:

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

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

Gives you ls and a whole lot more!

给你 ls 和更多!

回答by varagrawal

Easiest way I have found is:

我发现的最简单的方法是:

  1. Install Git for Windows
  2. Add the bindirectory of Git to your Path variable. Mine was located in C:\Program Files\Git\usr\bin.
  3. Start a command prompt and enjoy lsin all its glory.
  1. 为 Windows安装Git
  2. binGit的目录添加到您的 Path 变量中。我的位于C:\Program Files\Git\usr\bin.
  3. 启动命令提示符并享受ls它的所有荣耀。

回答by STM

I have a solution but it's dirty:

我有一个解决方案,但它很脏:

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

创建一个仅包含“dir”的名为 ls.bat 的文件。

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

将它放在 C:\windows\system32(或 PATH env var 中的任何目录)中。

That (should) works!

那(应该)有效!

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

编辑:更一致的东西:https: //superuser.com/questions/49170/create-an-alias-in-windows-xp

回答by dthree

If you have Node.jsinstalled on your system, you can install it from Cash, a library I wrote for Linux commands on Windows:

如果您的系统上安装了Node.js,则可以从Cash安装它,这是我为 Windows 上的 Linux 命令编写的库:

npm install cash-ls -g

回答by buster

Windows command prompt for Vista/7 will allow NTFS symbolic links, run cmd.exe as administrator then:

Vista/7 的 Windows 命令提示符将允许 NTFS 符号链接,以管理员身份运行 cmd.exe 然后:

mklink ls %System%\dir.exe

Then set up your PATH environment variable to include the location of the link you just created.

然后设置您的 PATH 环境变量以包含您刚刚创建的链接的位置。

If you want more than just the 'ls' command, you should look into cygwin.

如果您想要的不仅仅是 'ls' 命令,您应该查看cygwin

EDIT- Just realized dir.exeis not a separate program, so this doesn't really work. But mklinkand cygwin are good things to know about.

编辑 - 刚刚意识到dir.exe不是一个单独的程序,所以这并没有真正起作用。但是mklink和 cygwin 是值得了解的好东西。

回答by jtlindsey

+1 on the post above suggesting to install git for windows and add the directory bin to your path variables.

+1 在上面的帖子中建议为 Windows 安装 git 并将目录 bin 添加到您的路径变量中。

Another way I got touch, ls, and a lot of other UNIX commands working in cmd.exe on my Windows 8 and Windows 7 machines.

我在 Windows 8 和 Windows 7 机器上的 cmd.exe 中使用 touch、ls 和许多其他 UNIX 命令的另一种方法。

Go to the following site to install Cygwin

到以下站点安装 Cygwin

https://www.cygwin.com/install.html

https://www.cygwin.com/install.html

Install the 32 or 64 bit version for your system. The default settings and packages should include what you need so you don't have to change anything once you get to the packages screen.

为您的系统安装 32 位或 64 位版本。默认设置和包应包含您需要的内容,因此您在进入包屏幕后无需更改任何内容。

After installation, copy the Cygwin folder path to your environment path variables. For example; if you installed cygwin to C:\Cygwin, you will add the following to your environment system path variables:

安装后,将 Cygwin 文件夹路径复制到您的环境路径变量中。例如; 如果您将 cygwin 安装到 C:\Cygwin,则将以下内容添加到您的环境系统路径变量中:

;C:\Cygwin\bin

;C:\Cygwin\bin

On my system I installed the 64bit version and the default folder name and path was C:\cygwin64. So i added the following to my system environment path variables:

在我的系统上,我安装了 64 位版本,默认文件夹名称和路径是 C:\cygwin64。所以我在我的系统环境路径变量中添加了以下内容:

;C:\cygwin64\bin

;C:\cygwin64\bin

Restart your terminal if it's open. Then type ls and you'll see a directory listing.

如果终端打开,请重新启动它。然后键入 ls,您将看到一个目录列表。

See the following if you are not familiar with setting PATH environment variables:

如果您不熟悉设置 PATH 环境变量,请参阅以下内容:

Superuser Link 1

超级用户链接 1

Superuser Link 2

超级用户链接 2

回答by devio

If you just want to have cmd recognize lsas an alias for dir, you can use the doskeycommand (from this answer on superuser).

如果您只想将 cmd 识别ls为 的别名dir,则可以使用该doskey命令(来自superuser 上的这个答案)。

This does not change the original command line parameter handling of the dir command.

这不会改变 dir 命令的原始命令行参数处理。

回答by Nerdtron

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

您也可以使用cygwin并直接使用 ls 命令以及您可能习惯的所有其他 unix 命令行工具。