后订单查找-exec?


0

我想使用'find -exec'从一个组织中删除某些目录

find $rootdir -type d -name target -exec rm -rf {} \;

我收到错误消息

find: `foo/bar/target': No such file or directory

因为'find -exec'显然是按预定顺序工作的,即先完成工作,然后拜访孩子。我不想简单地将错误消息重定向到/ dev / null,因为它们可能很有意义。有什么建议么?


SO的题外话;属于对超级用户
防爆Umbris

Answers:


2

您正在寻找-dor -depth选项

 -depth  Always true; same as the -d option.

 -d      Cause find to perform a depth-first traversal, i.e., directories
         are visited in post-order and all entries in a directory will be
         acted on before the directory itself.  By default, find visits
         directories in pre-order, i.e., before their contents.  Note, the
         default is not a breadth-first traversal.

注意-depth,如果添加数字,它会改变含义。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.