This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
-r“递归”
-f“force”(禁止确认消息)
小心!
-r "recursive"
-f "force" (suppress confirmation messages)
Be careful!
将删除当前目录中的所有内容(文件夹和文件)。
但要小心! 仅当您完全确定您位于正确的目录中时才执行此命令。
Would remove everything (folders & files) in the current directory.
But be careful! Only execute this command if you are absolutely sure, that you are in the right directory.
是的,有。
-r
选项告诉rm
是 r 递归的,并删除以其参数为根的整个文件层次结构;换句话说,如果给定一个目录,它将删除其所有内容,然后执行有效的 rmdir 操作。您应该知道的另外两个选项是
-i
和-f
。-i
代表i互动;它会让rm
在删除每个文件之前提示您。-f
代表force;它会继续删除所有内容而不询问。-i
更安全,但-f
更快;仅当您绝对确定您正在删除正确的内容时才使用它。您可以使用-r
指定这些,也可以不指定;这是一个独立的设置。和往常一样,您可以组合开关:
rm -r -i
只是rm -ri
,rm -r -f
是>rm -rf
。另请注意,您正在学习的内容适用于每个 Unix 操作系统上的
bash
:OS X、Linux、FreeBSD 等。事实上,rm
的语法与几乎每个 Unix 操作系统上的每个 shell。 OS X 在本质上是一个 BSD Unix 系统。Yes, there is. The
-r
option tellsrm
to be recursive, and remove the entire file hierarchy rooted at its arguments; in other words, if given a directory, it will remove all of its contents and then perform what is effectively anrmdir
.The other two options you should know are
-i
and-f
.-i
stands for interactive; it makesrm
prompt you before deleting each and every file.-f
stands for force; it goes ahead and deletes everything without asking.-i
is safer, but-f
is faster; only use it if you're absolutely sure you're deleting the right thing. You can specify these with-r
or not; it's an independent setting.And as usual, you can combine switches:
rm -r -i
is justrm -ri
, andrm -r -f
isrm -rf
.Also note that what you're learning applies to
bash
on every Unix OS: OS X, Linux, FreeBSD, etc. In fact,rm
's syntax is the same in pretty much every shell on every Unix OS. OS X, under the hood, is really a BSD Unix system.我正在寻找一种方法来删除目录中的所有文件,除了我想保留的一些目录和文件。我设计了一种使用 find 来做到这一点的方法:
本质上,它使用正则表达式来选择要从结果中排除的目录,然后删除剩余的文件。
I was looking for a way to remove all files in a directory except for some directories, and files, I wanted to keep around. I devised a way to do it using find:
Essentially it uses regex to select the directories to exclude from the results then removes the remaining files.