I ran into problems using find
with -delete
due to the intentional behavior of find
(i.e. refusing to delete if the path starts with ./, which they do in my case) as stated in its man page:
-delete
Delete found files and/or directories. Always returns true. This executes from the current working directory as find recurses down the tree. It will not attempt to delete a filename with a "/" character in its pathname relative to "." for security reasons.
Depth-first traversal processing is implied by this option.
Following symlinks is incompatible with this option.
Instead, I was able to just do
find . -type d -name 'received_*_output' -exec rm -r {} +
For your case, it seems that quoting the glob (asterisk, *) was the solution, but I wanted to provide my answer in case anyone else had the similar problem.
NOTE: Previously, my answer was to do the following, but @Wildcard pointed out the security flaws in doing that in the comments.
find . -type d -name 'received_*_output' | xargs rm -r
sudo find . -type d -name "build" -exec rm -r {} +
Does the trick for me :) – raz Mar 10 '21 at 12:57