与所有的UNIX下使用find其内容删除目录 [英] Remove a directory with all of its contents using find under unix

查看:184
本文介绍了与所有的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其内容删除目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆