如果要删除我们使用的所有文件和目录,请rm -rf *.
If we want to delete all files and directories we use, rm -rf *.
但是,如果我想一次删除所有文件和目录,除了一个特定文件,该怎么办?
But what if i want all files and directories be deleted at a shot, except one particular file?
有什么命令吗? rm -rf *可以轻松删除,但可以删除我最喜欢的文件/目录.
Is there any command for that? rm -rf * gives the ease of deletion at one shot, but deletes even my favourite file/directory.
预先感谢
推荐答案find 可以成为一个很好的朋友:
find can be a very good friend:
$ ls a/ b/ c/ $ find * -maxdepth 0 -name 'b' -prune -o -exec rm -rf '{}' ';' $ ls b/ $说明:
-
find * -maxdepth 0:选择*选择的所有内容,而无需进入任何目录
find * -maxdepth 0: select everything selected by * without descending into any directories
-name 'b' -prune:请勿打扰(-prune)与条件-name 'b'
-name 'b' -prune: do not bother (-prune) with anything that matches the condition -name 'b'
-o -exec rm -rf '{}' ';':调用rm -rf进行其他操作
另外,另一种可能更简单的方法是移动或重命名您的收藏夹目录,以免受到干扰:
By the way, another, possibly simpler, way would be to move or rename your favourite directory so that it is not in the way:
$ ls a/ b/ c/ $ mv b .b $ ls a/ c/ $ rm -rf * $ mv .b b $ ls b/更多推荐
使用查找
发布评论