Find directory, if match then don't recurse

Clash 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.
find osx
add a comment |Â
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.
find osx
@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/platformswouldn't be searched because/usr/local/var/lib/android-sdkalready 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 befind / ! -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
add a comment |Â
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.
find osx
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
find osx
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/platformswouldn't be searched because/usr/local/var/lib/android-sdkalready 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 befind / ! -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
add a comment |Â
@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/platformswouldn't be searched because/usr/local/var/lib/android-sdkalready 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 befind / ! -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
add a comment |Â
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.
Thanks... isaac. Nice name
â Isaac
Sep 13 at 1:21
add a comment |Â
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.
Thanks... isaac. Nice name
â Isaac
Sep 13 at 1:21
add a comment |Â
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.
Thanks... isaac. Nice name
â Isaac
Sep 13 at 1:21
add a comment |Â
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.
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.
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
add a comment |Â
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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
@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/platformswouldn't be searched because/usr/local/var/lib/android-sdkalready 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 befind / ! -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