与所有的UNIX下使用find其内容删除目录

编程入门 行业动态 更新时间:2024-10-28 20:22:52
本文介绍了与所有的UNIX下使用find其内容删除目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我写一个shellscript里,它删除所有的发现。???文件夹及其内容。我写这样的:

I am writing a ShellScript that deletes every found.??? folders with its contents. I wrote this:

find $DRIVE -name 'found.???' -type d -exec rm -r {} \;

据我想要做什么,但给这个错误:

It does what I want, but gives this error:

find: „/media/.../found.000": No such file or directory find: „/media/.../found.001": No such file or directory

我能做些什么呢?谢谢!

What can I do with this? Thanks!

推荐答案

这是不是一个真正的问题。 找到是要pre-过程中的一些成果,当它试图删除一些目录已经被删除,你会得到标准错误。

This isn't really an issue. find is going to pre-process some results and when it tries to delete some directories which have already been deleted, you will get the stderr.

您可以忽略该错误消息,使用 -depth ,使其在DFS遍历,或迫使它 -prune 的目录。即

You can either ignore the error messages, use -depth to make it traverse in DFS, or force it to -prune the directories. i.e.

find "$DRIVE" -mindepth 1 -depth -name 'found.???' -type d -exec rm -r {} \;

find "$DRIVE" -mindepth 1 -name 'found.???' -type d -prune -exec rm -r {} \;

的注意, mindepth 1 ,所以你不小心删除$ DRIVE是很重要的

Note, mindepth 1 is important so you don't accidentally delete "$DRIVE"

更多推荐

与所有的UNIX下使用find其内容删除目录

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

发布评论

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

>www.elefans.com

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