Find directory, if match then don't recurse

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












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:



/usr/local/var/lib/android-sdk
/usr/local/var/lib/android-sdk/platforms/android-23
/usr/local/var/lib/android-sdk/platforms/android-24
/usr/local/var/lib/android-sdk/platforms/android-25
/usr/local/var/lib/android-sdk/platforms/android-26
/usr/local/var/lib/android-sdk/platforms/android-19
/usr/local/var/lib/android-sdk/platforms/android-28
/usr/local/var/lib/android-sdk/platforms/android-N
/usr/local/var/lib/android-sdk/system-images/android-23
/usr/local/var/lib/android-sdk/system-images/android-19
/usr/local/var/lib/android-sdk/system-images/android-N
...
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-15
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-16
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-18
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-20
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-21
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-19
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-10
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-17


I would like to get:



/usr/local/var/lib/android-sdk
/Library/Frameworks/Xamarin.Android.framework


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










share|improve this question























  • @Goro how? I need it to search the subdirs but only if it doesn't match
    – Isaac
    Sep 13 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 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 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*"
    – Goro
    Sep 13 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 at 0:58















up vote
0
down vote

favorite












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:



/usr/local/var/lib/android-sdk
/usr/local/var/lib/android-sdk/platforms/android-23
/usr/local/var/lib/android-sdk/platforms/android-24
/usr/local/var/lib/android-sdk/platforms/android-25
/usr/local/var/lib/android-sdk/platforms/android-26
/usr/local/var/lib/android-sdk/platforms/android-19
/usr/local/var/lib/android-sdk/platforms/android-28
/usr/local/var/lib/android-sdk/platforms/android-N
/usr/local/var/lib/android-sdk/system-images/android-23
/usr/local/var/lib/android-sdk/system-images/android-19
/usr/local/var/lib/android-sdk/system-images/android-N
...
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-15
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-16
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-18
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-20
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-21
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-19
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-10
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-17


I would like to get:



/usr/local/var/lib/android-sdk
/Library/Frameworks/Xamarin.Android.framework


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










share|improve this question























  • @Goro how? I need it to search the subdirs but only if it doesn't match
    – Isaac
    Sep 13 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 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 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*"
    – Goro
    Sep 13 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 at 0:58













up vote
0
down vote

favorite









up vote
0
down vote

favorite











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:



/usr/local/var/lib/android-sdk
/usr/local/var/lib/android-sdk/platforms/android-23
/usr/local/var/lib/android-sdk/platforms/android-24
/usr/local/var/lib/android-sdk/platforms/android-25
/usr/local/var/lib/android-sdk/platforms/android-26
/usr/local/var/lib/android-sdk/platforms/android-19
/usr/local/var/lib/android-sdk/platforms/android-28
/usr/local/var/lib/android-sdk/platforms/android-N
/usr/local/var/lib/android-sdk/system-images/android-23
/usr/local/var/lib/android-sdk/system-images/android-19
/usr/local/var/lib/android-sdk/system-images/android-N
...
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-15
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-16
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-18
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-20
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-21
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-19
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-10
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-17


I would like to get:



/usr/local/var/lib/android-sdk
/Library/Frameworks/Xamarin.Android.framework


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










share|improve this question















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:



/usr/local/var/lib/android-sdk
/usr/local/var/lib/android-sdk/platforms/android-23
/usr/local/var/lib/android-sdk/platforms/android-24
/usr/local/var/lib/android-sdk/platforms/android-25
/usr/local/var/lib/android-sdk/platforms/android-26
/usr/local/var/lib/android-sdk/platforms/android-19
/usr/local/var/lib/android-sdk/platforms/android-28
/usr/local/var/lib/android-sdk/platforms/android-N
/usr/local/var/lib/android-sdk/system-images/android-23
/usr/local/var/lib/android-sdk/system-images/android-19
/usr/local/var/lib/android-sdk/system-images/android-N
...
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-15
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-16
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-18
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-20
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-21
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-19
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-10
/Library/Frameworks/Xamarin.Android.framework/Versions/5.1.2-1/lib/mandroid/platforms/android-17


I would like to get:



/usr/local/var/lib/android-sdk
/Library/Frameworks/Xamarin.Android.framework


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







find osx






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 13 at 6:01









Goro

5,45552460




5,45552460










asked Sep 13 at 0:09









Isaac

1033




1033











  • @Goro how? I need it to search the subdirs but only if it doesn't match
    – Isaac
    Sep 13 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 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 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*"
    – Goro
    Sep 13 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 at 0:58

















  • @Goro how? I need it to search the subdirs but only if it doesn't match
    – Isaac
    Sep 13 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 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 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*"
    – Goro
    Sep 13 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 at 0:58
















@Goro how? I need it to search the subdirs but only if it doesn't match
– Isaac
Sep 13 at 0:26




@Goro how? I need it to search the subdirs but only if it doesn't match
– Isaac
Sep 13 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 at 0:37




@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 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 at 0:39




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 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*"
– Goro
Sep 13 at 0:50





If you want to find all the files except the ones that have *android* in it, then your command should be find / ! -name "*android*"
– Goro
Sep 13 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 at 0:58





@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 at 0:58











1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










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).


Simplified:



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.






share|improve this answer






















  • Thanks... isaac. Nice name
    – Isaac
    Sep 13 at 1:21










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f468674%2ffind-directory-if-match-then-dont-recurse%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










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).


Simplified:



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.






share|improve this answer






















  • Thanks... isaac. Nice name
    – Isaac
    Sep 13 at 1:21














up vote
3
down vote



accepted










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).


Simplified:



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.






share|improve this answer






















  • Thanks... isaac. Nice name
    – Isaac
    Sep 13 at 1:21












up vote
3
down vote



accepted







up vote
3
down vote



accepted






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).


Simplified:



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.






share|improve this answer














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).


Simplified:



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.







share|improve this answer














share|improve this answer



share|improve this answer








edited Sep 15 at 9:10

























answered Sep 13 at 1:02









Isaac

7,33411035




7,33411035











  • Thanks... isaac. Nice name
    – Isaac
    Sep 13 at 1:21
















  • Thanks... isaac. Nice name
    – Isaac
    Sep 13 at 1:21















Thanks... isaac. Nice name
– Isaac
Sep 13 at 1:21




Thanks... isaac. Nice name
– Isaac
Sep 13 at 1:21

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f468674%2ffind-directory-if-match-then-dont-recurse%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)