0

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?

stackprotector
  • 4,982
  • 4
  • 12
  • 36
deadcoder0904
  • 3,758
  • 1
  • 27
  • 91
  • 2
    `rd /q /s` is for CMD, but it looks like you're running PowerShell. Nothing stops you from using CMD instead. And this question has absolutely nothing to do with the terminal you're using. It's a shell question. – Eryk Sun May 03 '20 at 12:01
  • @ErykSun I got this error `Remove-Item : A positional parameter cannot be found that accepts argument '/s'.`. I can easily delete the folder using git bash too. But that doesn't answer my question. Of course, it has relation because the new Windows Terminal Preview will be default soon from programmers. It has potential. Give it a shot & you'll see. I just need to delete the folder using that new Terminal. I don't understand why it's so hard to understand. – deadcoder0904 May 03 '20 at 14:49
  • 1
    The terminal is not the shell. You seem to be confusing the two. CMD, PowerShell, bash, etc all work as well in the classic conhost.exe terminal/console, the one that Windows console applications allocate if they aren't spawned with a terminal already attached. A console or terminal provides a UI for text input and output, with varying degrees of UI support for programs in terms of either API functions and IOCTLs or standard escape sequences. – Eryk Sun May 03 '20 at 15:22
  • 1
    Again, you're using PowerShell, in which `rd` is an alias for `remove-item` and doesn't support the same syntax as CMD's `rd` command. Open a CMD shell to run `rd /q /s` -- in whatever terminal or console you prefer. If you run cmd.exe from Explorer, you'll get the classic conhost.exe terminal. In Windows Terminal you can run CMD in a new tab, or just run cmd.exe from PowerShell. – Eryk Sun May 03 '20 at 15:28
  • @ErykSun Ahh that's even more confusing, anyways got an answer :) – deadcoder0904 May 04 '20 at 08:58

2 Answers2

10

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
stackprotector
  • 4,982
  • 4
  • 12
  • 36
-1

try using this :-

rmdir /s directory_name
Anit Aggarwal
  • 87
  • 1
  • 7