On my Mac, I screwed up my android SDK installation. I was looking to clean it out by finding all references to "android".

The issue is, when I run the command find / -name "*android*" I get quite an extensive list.

Instead of this list:


I would like to get:


It doesn't search the subdirectories if the directory matches.

  • @Goro how? I need it to search the subdirs but only if it doesn't match – Isaac Sep 13 '18 at 0:26
  • @Goro I thought the question outlined it fairly clearly, I want the result to, no matter how deep, stop searching the subdirectories of paths that match *android* – Isaac Sep 13 '18 at 0:37
  • eg: /usr/local/var/lib/android-sdk/platforms wouldn't be searched because /usr/local/var/lib/android-sdk already matches *android* – Isaac Sep 13 '18 at 0:39
  • If you want to find all the files except the ones that have *android* in it, then your command should be find / ! -name "*android*" – user88036 Sep 13 '18 at 0:50
  • @Goro No, I want to find folders that match *android*, but I don't want to see the child folders of these folders – Isaac Sep 13 '18 at 0:58

If you only need directories:

find . -type d -iname '*android*' -a \( -prune  \)

Coments on code:

.             # Present directory
-type d       # Only directories
-iname        # Instead of `-name` to also match "Android" (ignore case).
'*android*'   # Pattern of name to search
-a            # Force the execution of next option on matching names.
              # probably redundant as all options are evaluated with an
              # implicit and in find
              # but: makes the intent explicitly clear.
\( -prune  \) # Remove the whole directory from further examination.
              # braces also optional (as it is only one command).


find . -type d -iname '*android*' -prune

If you also want files:

find . -iname '*android*' -a \( -prune  \)

Caveat: this will report all files found and then directories. It is not clear if if a file named "android" is found that the corresponding directory should be avoided.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.