使用查找

编程入门 行业动态 更新时间:2024-10-23 23:28:34
本文介绍了使用查找-删除所有文件/目录(在Linux中),除任何一个以外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果要删除我们使用的所有文件和目录,请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/

更多推荐

使用查找

本文发布于:2023-10-31 12:55:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546147.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!