Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"rm -rf" equivalent for Windows?

Tags:

windows

cmd

wsh

I need a way to recursively delete a folder and its children.

Is there a prebuilt tool for this, or do I need to write one?

DEL /S doesn't delete directories.

DELTREE was removed from Windows 2000+

like image 245
FlySwat Avatar asked Sep 18 '08 23:09

FlySwat


People also ask

What is rm RF in Windows?

rm -rf a directory. single command to delete directory and all of its children. shell remove direcotory and its contents. Removing Folders In CMD. remove directory windows commnad.

What is the command to delete a directory in Windows?

To remove a directory, just use the command rmdir <directory name> . Note: Any directories deleted with the rmdir command cannot be recovered. Be very careful where and how you use this command.

What is Windows equivalent of sudo?

There is no sudo command in Windows. The nearest equivalent is "run as administrator." You can do this using the runas command with an administrator trust-level, or by right-clicking the program in the UI and choosing "run as administrator."


2 Answers

RMDIR or RD if you are using the classic Command Prompt (cmd.exe):

rd /s /q "path" 

RMDIR [/S] [/Q] [drive:]path

RD [/S] [/Q] [drive:]path

/S Removes all directories and files in the specified directory in addition to the directory itself. Used to remove a directory tree.

/Q Quiet mode, do not ask if ok to remove a directory tree with /S

If you are using PowerShell you can use Remove-Item (which is aliased to del, erase, rd, ri, rm and rmdir) and takes a -Recurse argument that can be shorted to -r

rd -r "path" 
like image 82
Duncan Smart Avatar answered Sep 20 '22 13:09

Duncan Smart


admin:

takeown /r /f folder cacls folder /c /G "ADMINNAME":F /T rmdir /s folder 

Works for anything including sys files

EDIT: I actually found the best way which also solves file path too long problem as well:

mkdir \empty robocopy /mir \empty folder 
like image 20
wbkang Avatar answered Sep 20 '22 13:09

wbkang