关于cmd:’ls’不被识别为内部或外部命令,可操作程序或批处理文件

'ls' is not recognized as an internal or external command, operable program or batch file

无法将" ls"识别为内部或外部命令,可操作程序或批处理文件。
当我尝试浏览文件夹中的文件时出现此错误。

  • cmd定期打开(不作为管理员)。
  • 我最近下载了适用于python的anaconda。在安装过程中,有时允许添加不推荐的PATH。
    'ls'曾经很好地工作

    这是路径

    enter image description here


我相当确定ls命令是用于Linux的,而不是Windows(我假设您所使用的Windows是指cmd,这是Windows OS的命令行)。

您应该改用dir,它与Windows中的ls等效。

编辑(因为这篇文章似乎获得了这么多的意见:)):

您不能在cmd上使用ls,因为它不是Windows附带的,但是您可以在其他终端程序(例如GitBash)上使用它。请注意,如果服务器基于linux并且正在使用FTP中的FTP,则ls可能在某些FTP服务器上工作。

Windows上的dirls相似。要找出可用的各种选项,只需执行dir/?

如果您确实要使用ls,则可以安装第三方工具以允许您在Windows上运行unix命令。这样的程序是Microsoft Windows Subsystem for Linux(链接到docs)。


我们可以在Windows cmd中使用ls和许多其他Linux命令。只需按照以下步骤。

脚步:

1)在您的计算机上安装Git-https://git-scm.com/downloads。

2)安装Git后,转到安装Git的文件夹。
通常,它将在C drive文件夹中,然后在Program Files文件夹中。

3)在Program Files文件夹中,您将找到名为Git的文件夹,找到bin文件夹
它位于Git文件夹中的usr文件夹中。

在我的情况下,bin文件夹的位置为-C:\Program Files\Git\usr\bin

4)在系统的路径变量中添加此位置(C:\Program Files\Git\usr\bin)
环境变量。

5)完成。重新启动cmd并尝试运行ls和其他Linux命令。


如果要在Windows上使用Unix Shell命令,则可以使用Windows Powershell,它包括Windows和Unix命令作为别名。您可以在文档中找到更多信息。

PowerShell supports aliases to refer to commands by alternate names.
Aliasing allows users with experience in other shells to use common
command names that they already know for similar operations in
PowerShell.

The PowerShell equivalents may not produce identical results. However,
the results are close enough that users can do work without knowing
the PowerShell command name.