【发布时间】:2021-06-25 18:40:25
【问题描述】:
在cmd中你可以运行C:\path> dir /A,它会列出一个文件夹中的所有文件(例如包括隐藏的.git/目录)。
您可以在 cmd 和 PowerShell 中运行 dir。
您可以在 cmd 中运行 dir /A,但不能在 PowerShell 中运行 dir /A。它会抱怨:powershell error pic
同样,在 PowerShell 中,您可以像在 Linux bash 中一样运行 PS C:\path> ls,但不能像在所有 Linux 中那样运行 ls -a,或者像在 Ubuntu 中那样运行 la。
这是为什么?我的意思是为什么微软会如此部分地实施事情?那么如何在 PowerShell 中列出文件夹中的所有文件,例如 cmd 中的 dir /A 或 bash 中的 ls -a?
我遇到这种情况是因为我仍在 Windows 7 中运行这些,还是在 Windows 10 上相同?
【问题讨论】:
-
试试
dir -force。它只是Get-ChildItem的别名,并不意味着参数兼容。 -
@zett42 是的,我刚刚发现 PowerShell 中的
dir和ls实际上是来自help dir和help ls的Get-ChildItem。无论如何,您的解决方案有效,我也认为ls -force的工作原理相同。只是我只需要记住至少 3 种不同的方式在 cmd、PowerShell 和 Linux 中做“同样的事情”。 -
From : stackoverflow.com/questions/1479663/…
cmd /r dir /a也可以工作,可能还有许多其他解决方案或黑客。但我不认为它们是很好的解决方案...... -
至于这个
It's just that I just have to remember at least 3 different ways to do "same thing" in cmd, PowerShell, and Linux,为什么?只需避免使用 cmd.exe,始终留在 PS 中,在 Windows/Linux 上,坚持使用 PS 命令。您始终可以根据需要从 PS 中选择其他可执行文件。在此处查看详细信息:• PowerShell: Running Executables : https://social.technet.microsoft.com/wiki/contents/articles/7703.powershell-running-executables.aspx
标签: powershell cmd windows-10 windows-7