windows “rm -rf”相当于Windows?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/97875/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"rm -rf" equivalent for Windows?
提问by FlySwat
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.
DEL /S
不删除目录。
DELTREE
was removed from Windows 2000+
DELTREE
已从 Windows 2000+ 中删除
回答by Duncan Smart
RMDIR or RD if you are using the classic Command Prompt (cmd.exe):
如果您使用的是经典命令提示符 (cmd.exe),则为 RMDIR 或 RD:
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
RMDIR [/S] [/Q] [驱动器:]路径
RD [/S] [/Q] [驱动器:]路径
/S 除目录本身外,还删除指定目录中的所有目录和文件。用于删除目录树。
/Q 安静模式,不要询问是否可以使用 /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
如果您使用的是 PowerShell,则可以使用Remove-Item
(别名为del
, erase
, rd
, ri
, rm
and rmdir
)并接受一个-Recurse
可以缩写为的参数-r
rd -r "path"
回答by wbkang
admin:
行政:
takeown /r /f folder
cacls folder /c /G "ADMINNAME":F /T
rmdir /s folder
Works for anything including sys files
适用于包括 sys 文件在内的任何内容
EDIT: I actually found the best way which also solves file path too long problem as well:
编辑:我实际上找到了最好的方法,它也解决了文件路径太长的问题:
mkdir \empty
robocopy /mir \empty folder
回答by Jim McKeeth
RMDIR [/S][/Q] [drive:]path
RMDIR [/S][/Q] [drive:]path
RD [/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
/S
除目录本身外,还删除指定目录中的所有目录和文件。 用于删除目录树。/Q
安静模式,不要询问是否可以删除目录树/S
回答by user17481
You can install cygwin, which has rm
as well as ls
etc.
您可以安装 cygwin,它具有rm
以及ls
等。
回答by Sireesh Yarlagadda
Go to the path and trigger this command.
转到路径并触发此命令。
rd /s /q "FOLDER_NAME"
/s : Removes the specified directory and all subdirectories including any files. Use /s to remove a tree.
/s :删除指定目录和所有子目录,包括任何文件。使用 /s 删除树。
/q : Runs rmdir in quiet mode. Deletes directories without confirmation.
/q : 在安静模式下运行 rmdir。不经确认删除目录。
/? : Displays help at the command prompt.
/? : 在命令提示符下显示帮助。
回答by Clay
For deleting a directory (whether or not it exists) use the following:
要删除目录(无论是否存在),请使用以下命令:
if exist myfolder ( rmdir /s/q myfolder )
回答by Branan
rmdir /S /Q %DIRNAME%
rmdir /S /Q %DIRNAME%
回答by Artif3x
The accepted answer is great, but assuming you have Node installed, you can do this much more precisely with the node library "rimraf", which allows globbing patterns. If you use this a lot (I do), just install it globally.
接受的答案很好,但假设您安装了 Node,您可以使用节点库“rimraf”更精确地执行此操作,它允许使用通配模式。如果你经常使用它(我这样做),只需全局安装它。
yarn global add rimraf
then, for instance, a pattern I use constantly:
然后,例如,我经常使用的模式:
rimraf .\**\node_modules
or for a one-liner that let's you dodge the global install, but which takes slightly longer for the the package dynamic download:
或者对于让您避开全局安装的单行程序,但包动态下载所需的时间稍长:
npx rimraf .\**\node_modules
回答by Jeremy Ruten
Try this command:
试试这个命令:
del /s foldername
回答by cilerler
via Powershell
通过 Powershell
Remove-Item -Recurse -Force "TestDirectory"
via Command Prompt
通过命令提示符