find(1) removes as it should a directory, but after this it complains about

Christian Weisgerber naddy at
Wed Apr 22 15:00:18 UTC 2020

On 2020-04-20, Matthias Apitz <guru at> wrote:

> I've stumbled over something with find(1) which I would call a bug:
> $ mkdir foo
> $ find foo -type d -execdir rm -rv {} \;
> foo
> find: foo: No such file or directory

* sees the directory entry "foo";
* evalutes the expression for it, which as a side effect executes
  an action;
* tries to recurse into "foo", since it is a directory.

That's perfectly reasonable.  find(1) can't know that the action
removed the directory.  If your exec removes a directory, you should
tell find(1) to not recurse into it:

$ find foo -type d -prune -execdir rm -rv {} \;

Christian "naddy" Weisgerber                          naddy at

More information about the freebsd-questions mailing list