An alternative to using -depth is to -prune the directories that you're going to delete anyway to tell find not to bother trying to find files in them:
find . \( -name build -o -name obj -o -name '*.so' \) -prune -exec rm -rf {} + Also note that *.so needs to be quoted as otherwise it may be expanded by the shell to the list of .so files in the current directory.