“rm -rf"相当于 Windows PowerShell? [英] "rm -rf" equivalent for Windows PowerShell?

查看:56
本文介绍了“rm -rf"相当于 Windows PowerShell?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了rm -rf"等效于 Windows 的问题?.而且我还尝试了以下命令:

I have already read the question "rm -rf" equivalent for Windows?. And I have also tried the following commands:

$ rm app
$ rmdir /s /q app
$ rmdir -s -q app
$ rd /s /q app

和许多其他变体.它总是提示我:

and many other variations. It always prompts me with:

位于 C:\ThisDirectoryDoesNotExist\app\ 的项目有子项,并且未指定 Recurse 参数.如果继续,所有孩子都将与项目一起被移除.确定要继续吗?

The item at C:\ThisDirectoryDoesNotExist\app\ has children and the Recurse parameter was not specified. If you continue, all children will be removed with the item. Are you sure you want to continue?

[Y] 是 [A] 全部是 [N] 否 [L] 全部否 [S] 暂停 [?] 帮助(默认为Y"):A

[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): A

当我选择A时,它会抛出一个错误:

And when I choose A, it throws an error:

rm : 无法删除项目C:\ThisDirectoryDoesNotExist\app.git\objects\pack\pack-45e426475eb08ff5042bf88556fbedd3956fba53.idx:你没有有足够的访问权限来执行此操作.

rm : Cannot remove item C:\ThisDirectoryDoesNotExist\app.git\objects\pack\pack-45e426475eb08ff5042bf88556fbedd3956fba53.idx: You do not have sufficient access rights to perform this operation.

我该怎么做?

推荐答案

只需按照建议指定 recurse 参数:

Just specify the recurse parameter as suggested:

rm -r app

如果文件夹包含隐藏文件,添加-Force参数:

If the folder contains hidden files, add the -Force parameter:

rm -r -fo app

这是以下的缩写形式:

Remove-Item -Recurse -Force -Path app

如果您没有适当的访问权限,那么您当然不能删除它.

If you do not have proper access rights, then you can of course not delete it.

背景

rmdirrd 是可以在命令提示符下调用的命令(不是可执行文件).rm 默认不可用.例如,如果您安装了 MinGW 环境,则所有三个术语也可能指向可执行文件.但是它们在 PowerShell 中不可用,因为 PowerShell 使用这些词作为 cmdlet Remove-Item:

rmdir and rd are commands (not executables) you can call on the command prompt. rm is not available by default. All three terms may also point to executables if you have a MinGW environment installed, for example. But they will not be available in PowerShell, because PowerShell uses those words as aliases for the cmdlet Remove-Item:

PS> 'rm', 'rmdir', 'rd' | Get-Command

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           rm -> Remove-Item
Alias           rmdir -> Remove-Item
Alias           rd -> Remove-Item

如果您有一些可作为可执行文件的工具,您仍然可以通过指定它们的完整路径在 PowerShell 中访问它们,例如:

If you have some of the tools available as executables, you can still access them in PowerShell by specifying the full path to them, like:

PS> C:\path\to\MinGW\msys\1.0\bin\rm.exe

但让我们坚持使用 Remove-Item.由于它是一个 cmdlet,它需要某些参数或开关,例如 -Recurse.您可以在此之前将它们缩写,与其他可能的参数相比,它们保持明确.因此,您可以使用:

But let's stick to Remove-Item. As it is a cmdlet, it expects certain parameters or switches, like -Recurse. You can abbreviate them until to that point, they remain unambiguous compared to other possible parameters. Therefore you can use:

rm -r

例如在 bash 中,您还可以像这样传递两个参数:

which looks like in bash, for example, where you can also pass two parameters like this:

rm -rf

当您将此命令发送到 PowerShell 时,它会尝试将 -rf 与不存在的以 rf 开头的参数匹配.在 PowerShell 中,您必须将每个参数单独传递给 cmdlet.要传递-Force参数,你至少要写-fo,因为还有一个参数-Filter,因此-f 会模棱两可.

When you send this command to PowerShell, it will try to match -rf to a parameter that begins with rf, which does not exist. In PowerShell you have to pass each parameter individually to a cmdlet. To pass the -Force parameter, you have to write at least -fo, because there is also a parameter -Filter and thus -f would be ambiguous.

总而言之,要在 PowerShell 中从 bash 获得等效于 rm -rf 的内容,您至少必须编写:

In conclusion, to get the equivalent of rm -rf from bash in PowerShell, you have to write at least:

rm -r -fo

这篇关于“rm -rf"相当于 Windows PowerShell?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆