问题
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:
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] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): A
And when I choose A, it throws an error:
rm : Cannot remove item C:\ThisDirectoryDoesNotExist\app.git\objects\pack\pack-45e426475eb08ff5042bf88556fbedd3956fba53.idx: You do not have sufficient access rights to perform this operation.
How do I do it?
回答1:
Just specify the recurse parameter as suggested:
rm -r app
If the folder contains hidden files, add the -Force parameter:
rm -r -fo app
This is the short form of:
Remove-Item -Recurse -Force -Path app
If you do not have proper access rights, then you can of course not delete it.
Background
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
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
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
which looks like in bash, for example, where you can also pass two parameters like this:
rm -rf
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.
In conclusion, to get the equivalent of rm -rf from bash in PowerShell, you have to write at least:
rm -r -fo
回答2:
try using this :-
rmdir /s directory_name
来源:https://stackoverflow.com/questions/61573115/rm-rf-equivalent-for-windows-powershell