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

发布于 2025-01-07 11:25:10 字数 64 浏览 4 评论 0原文

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

我怎样才能做到这一点?

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

How can I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(20

ˉ厌 2025-01-14 11:25:11

当然 ls 不能作为批处理的 unix 命令。如果您检查 %1 中的 -l 或 -a 等以及它们的所有组合,它将起作用......

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...

春风十里 2025-01-14 11:25:11

这是我的 C# 源代码和二进制文件

只需在某处添加 ls.exe 并将路径添加到 path 环境变量即可。

Here is my C# source code and binary.

Just add ls.exe somewhere and add the path to the path environment variable.

祁梦 2025-01-14 11:25:10

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

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

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

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

分開簡單 2025-01-14 11:25:10

您可以:

  • 创建一个名为 ls.bat 的批处理文件,并让它包含 dir 命令,仅
  • 添加 ls.bat 文件所在的目录添加到您的 PATH 环境变量,

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

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.

如若梦似彩虹 2025-01-14 11:25:10

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

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

为您提供 ls 以及更多内容!

Its an old question but for the record:

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

Gives you ls and a whole lot more!

野生奥特曼 2025-01-14 11:25:10

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

  1. 安装 Git for Windows
  2. 添加 bin Git 目录添加到您的 Path 变量中。我的位于C:\Program Files\Git\usr\bin
  3. 启动命令提示符并享受 ls 的所有荣耀。

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.
佞臣 2025-01-14 11:25:10

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

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

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

那(应该)有效!

编辑:更一致的东西: https://superuser.com/questions/49170/create- Windows XP 中的别名

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

别念他 2025-01-14 11:25:10

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

npm install cash-ls -g

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

npm install cash-ls -g
呆头 2025-01-14 11:25:10

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

mklink ls %System%\dir.exe

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

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

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

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

mklink ls %System%\dir.exe

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

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

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

森林散布 2025-01-14 11:25:10

如果您只想让 cmd 将 ls 识别为 dir 的别名,则可以使用 doskey 命令(来自 这个关于超级用户的答案)。

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

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

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

勿挽旧人 2025-01-14 11:25:10

我的 ls.bat 位于下面

@dir %*

,可以传输 cli args

ls /b
ls /w

将其放入 %windir% 或 %PATH% 变量中的任何目录中。

只需确保使用 ANSI 编码保存文件即可:)

my ls.bat was below

@dir %*

that can transfer cli args

ls /b
ls /w

put it in %windir% or any directory in your %PATH% variable.

Just make sure you save the file with ANSI encoding :)

菩提树下叶撕阳。 2025-01-14 11:25:10

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

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

转到以下站点安装 Cygwin

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

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

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

;C:\Cygwin\bin

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

;C:\cygwin64\bin

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

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

超级用户链接 1

超级用户链接 2

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

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.

Go to the following site to install Cygwin

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.

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:

;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:

;C:\cygwin64\bin

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

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

Superuser Link 1

Superuser Link 2

原谅过去的我 2025-01-14 11:25:10

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

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.

不寐倦长更 2025-01-14 11:25:10

最简单的方法是

  • 将 git
  • add C:\Program Files\Git\usr\bin 安装到你的路径变量中

,现在你可以使用 ls

The most easiest way is

  • install git
  • add C:\Program Files\Git\usr\bin to your path variable

now you can use ls

儭儭莪哋寶赑 2025-01-14 11:25:10

我推荐以下食谱。

  1. 使用 DOSKEY$* 创建 ls 命令。
  2. 通过将命令记录在 .bat/.cmd 文件中并将该文件的路径添加到注册表来使命令持久化。

例如,您的命令可能类似于
DOSKEY ls=dir
DOSKEY sublime="C:\Program Files\Sublime Text 2\sublime_text" $*
$* 对于接受参数的命令很有用。例如,在这里我希望能够执行 sublime my_code.c

cmd 的注册表位于 HKEY_CURRENT_USER ->软件->微软->命令处理器。使用文件(不是包含文件夹)的完整路径创建一个名为 AutoRun 的字符串值条目,例如 %USERPROFILE%\custom_command.cmd。然后每次运行 cmd 时,您的命令都会被加载!

您也可以向批处理文件添加更多有用的内容。有关示例模板,请参阅此处

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.

短暂陪伴 2025-01-14 11:25:10

对我有用的另一个解决方案是使用 UnxUtils,它从可执行文件(包括 lssedgrep)。

使用方法:下载源代码。解压缩。将 UnxUtils\usr\local\wbin 路径添加到 Windows PATH 变量。启动一个新的 CMD 实例。

Another solution that worked for me is to use UnxUtils, which adds multiple utilities from executable files (including ls, sed, and grep).

To use: download source code. Unzip. Add the UnxUtils\usr\local\wbin path to the Windows PATH variable. Start a new CMD instance.

伴我老 2025-01-14 11:25:10

使用 Windows 的 Linux 子系统的人可以从 Linux bash 调用 ls。以下命令在 System32 中创建 ls 命令:(

echo @bash -c "ls %*" > %systemroot%\system32\ls.bat

必须首先启用/安装 Linux 子系统功能)

Someone who uses Linux Subsystem for Windows could call ls from the Linux bash. The following Command creates the ls Command in System32:

echo @bash -c "ls %*" > %systemroot%\system32\ls.bat

(The Linux Subsystem feature must be enabled/installed first)

肩上的翅膀 2025-01-14 11:25:10

您可以遵循本指南:
https://gist.github.com/vladikoff/38307908088d58af206b

TL;DR< /strong>:将 /K path/to/custom/init_cmd.bat 传递给你的“shell启动”命令。

我使用 ConsoleZ 作为我的 shell 包装器,因此在我的情况下,我可以在“选项卡”中找到设置选项,然后将 shell 路径设置为 “C:\Windows\System32\cmd.exe”/KC: \cmd_init.bat""
像这样

其中 C:\cmd_init.bat 是包含我的宏的批处理脚本,这就是我想要的:

@echo off

doskey ls=dir /b
rem other macro stuff..

抱歉格式和其他错误,这是我第一次在这里回答。
我希望它有帮助!

You could follow this guide:
https://gist.github.com/vladikoff/38307908088d58af206b

TL;DR: pass /K path/to/custom/init_cmd.bat to your "shell startup" command.

I'm using ConsoleZ as my shell wrapper, so in my case I can find the setup option in "tabs", then I set the shell path to "C:\Windows\System32\cmd.exe "/K C:\cmd_init.bat""
like this.

Where C:\cmd_init.bat is the batch script containing my macros, here's what I would go for:

@echo off

doskey ls=dir /b
rem other macro stuff..

Sorry for formatting and other mistakes, this is my first time answering here.
I hope it helps!

破晓 2025-01-14 11:25:10

使用 doskey 键在 .bat 或 .cmd 文件中创建别名:

@echo off
title "ls command cmd bar"
doskey ls=echo off $T dir $* $T echo on

Enjoy =)

Create an alias in .bat or .cmd file using doskey key:

@echo off
title "ls command cmd bar"
doskey ls=echo off $T dir $* $T echo on

Enjoy =)

那些过往 2025-01-14 11:25:10

我记得旧 Unix 时代的一些内容

doskey ls=dir /D/OG $*
doskey ld=dir /AD /B /O $*
doskey ll=dir /A /O $*
doskey lo=dir /AD /Q $*
doskey h=doskey /history
doskey macros=doskey /macros
doskey z=cls
doskey pwd=cd
doskey whoami=echo %USERNAME%

A few that I remember from the old Unix days

doskey ls=dir /D/OG $*
doskey ld=dir /AD /B /O $*
doskey ll=dir /A /O $*
doskey lo=dir /AD /Q $*
doskey h=doskey /history
doskey macros=doskey /macros
doskey z=cls
doskey pwd=cd
doskey whoami=echo %USERNAME%
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文