find specific named directory while excluding specific named directory
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
find specific named directory while excluding specific named directory
Have no problem using find to search for directories with a specific name. Also don't have a problem using find to exclude directories with a specific name.
What has me stumped is doing both simultaneously. Finding directories with a specific name while also excluding other named directories seems to require voodoo.
One solution is piping to grep but I need a solution that only uses find. On our network we use a utility called snapshot (not the screen capture tool). Snapshot keeps several backups in a subdirectory called .snapshot. Not only does it keep several backups but .snapshot could exist in more that one place. This causes find to take an extremely long time to run. That's why piping to grep is not a solution.
Basically need to find directories named 'setup' while excluding directories name '.snapshot'. Tried several things with prune and '!' and nothing so far has worked.
Basically need to find directories named 'setup' while excluding directories name '.snapshot'. Tried several things with prune and '!' and nothing so far has worked.
I guess, you want to search directories named "setup" within your system and want to exclude those directories which also has a name "setup" and are inside ".snapshot" directory... Right? You can try following:
Code:
~$ find /path/to/search -type d -name '.snapshot' -prune -o -type d -name 'setup' -print
It will serach for all directories named "setup" and exclude ".snapshot".
I guess, you want to search directories named "setup" within your system and want to exclude those directories which also has a name "setup" and are inside ".snapshot" directory... Right? You can try following:
Code:
~$ find /path/to/search -type d -name '.snapshot' -prune -o -type d -name 'setup' -print
It will serach for all directories named "setup" and exclude ".snapshot".
I want to exclude all .snapshot directories. Your suggestion appears to be working. The find is still running but I haven't seen a '.snapshot' in the output yet. So far so good.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.