Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell Command: rm -rf

rm is to remove item, but what is the parameter -rf do or signify?


Whenever I typed help -rf it printed the entire list of available commands in powershell. What happens if you type rm -rf in powershell? From reading around I've gathered that it will delete everything on the drive? I'm not sure?

Also, is rm -rf same as rm -rf /

like image 619
BK_ Avatar asked May 04 '12 06:05

BK_


People also ask

How do you rm in PowerShell?

rm -rf /path/to/delete/ means rm (remove) with attributes r (recursive) and f (force) on the directory /path/to/remove/ and its sub-directories. Note that -f in PowerShell is ambiguous for -Filter and -Force and thus -fo needs to be used.

What is the PowerShell command to delete Remove a file?

Remove-Item cmdlet is used to delete a file by passing the path of the file to be deleted.

How do I Remove all files from a directory in PowerShell?

Every object in PowerShell has a Delete() method and you can use it to remove that object. To delete files and folders, use the Get-ChildItem command and use the Delete() method on the output. Here, this command will delete a file called “testdata. txt”.

How do you recursively delete a file in PowerShell?

Using PowerShell to Delete All Files Recursively If you need to also delete the files inside every sub-directory, you need to add the -Recurse switch to the Get-ChildItem cmdlet to get all files recursively.


2 Answers

PowerShell isn't UNIX. rm -rf is UNIX shell code, not PowerShell scripting.

  • This is the documentation for rm (short for Remove-Item) on PowerShell.
  • This is the documentation for rm on UNIX.

See the difference?

On UNIX, rm -rf alone is invalid. You told it what to do via rm for remove with the attributes r for recursive and f for force, but you didn't tell it what that action should be done on. rm -rf /path/to/delete/ means rm (remove) with attributes r (recursive) and f (force) on the directory /path/to/remove/ and its sub-directories.

The correct, equivalent command on PowerShell would be:

rm C:\path\to\delete -r -fo 

Note that -f in PowerShell is ambiguous for -Filter and -Force and thus -fo needs to be used.

like image 150
Mahmoud Al-Qudsi Avatar answered Sep 30 '22 20:09

Mahmoud Al-Qudsi


You have to use:

Remove-Item C:\tmp -Recurse -Force 

or (short)

rm C:\tmp -Recurse -Force 
like image 38
Kai Sternad Avatar answered Sep 30 '22 21:09

Kai Sternad