LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   find specific named directory while excluding specific named directory (https://www.linuxquestions.org/questions/linux-newbie-8/find-specific-named-directory-while-excluding-specific-named-directory-4175491539/)

sharky 01-16-2014 05:00 PM

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.

I am open to suggestions.

Many thanks in advance.

custangro 01-16-2014 05:17 PM

What have you tied so far?

Have you taken a look at the -prune and -maxdepth parameters?

--C

sharky 01-16-2014 05:29 PM

Quote:

Originally Posted by custangro (Post 5099412)
What have you tied so far?

Have you taken a look at the -prune and -maxdepth parameters?

--C

Here is a sample of what I've tried.

Quote:

find . -maxdepth 5 -type d -name setup -not -path "./.snapshot"
find . -maxdepth 5 -type d -name setup -not -path ".snapshot"
find . -maxdepth 5 -type d -name setup -not -path "*.snapshot"
find . -maxdepth 5 -type d -name setup -not -path "*/.snapshot"
find . -maxdepth 5 -type d -name setup -not -path "*/.snapshot/"
find . ! -path "*/.snapshot/*" -maxdepth 5 -type d -name setup
find . -maxdepth 5 ! -path "*/.snapshot/*" -type d -name setup
find . -maxdepth 5 -type d -name setup -and -not -path "*/.snapshot/"
find . -maxdepth 5 -type d -name setup -\! -name ".snapshot"
find . -maxdepth 5 -type d -name setup -\! -path "*/.snapshot/*"
find . -maxdepth 5 -type d -name setup -prune -o -path .snapshot
find . ! -path "*/\.snapshot/*"
find . ! -path "*/\.snapshot/*" -type d -name setup
find . -type d ! -path "*/\.snapshot/*" -type d -name setup
find . -maxdepth 5 -type d -name setup '.snapshot' -prune -o
find . -maxdepth 5 -type d -name setup \('.snapshot'\) -prune -o
find . -maxdepth 5 -type d -name setup \(.snapshot\) -prune -o
find . -maxdepth 5 -type d -name setup -exclude .snapshot
find . -maxdepth 5 -type d -name setup -prune .snapshot
find . -maxdepth 5 -type d -name setup -prune .snapshot

custangro 01-16-2014 06:07 PM

Try putting "prune" first...

Here is an example of what I use on my server

Code:

find . -name .snapshot -prune -o -name setup -type d
Something like that...I have a netapp and it leaves snapshot dirs all around...I had a similar issue

--C

sharky 01-17-2014 12:23 AM

Quote:

Originally Posted by custangro (Post 5099431)
Try putting "prune" first...

Here is an example of what I use on my server

Code:

find . -name .snapshot -prune -o -name setup -type d
Something like that...I have a netapp and it leaves snapshot dirs all around...I had a similar issue

--C

Didn't work.

Quote:

> find . -name .snapshot -prune -o -name setup -type d
./y/setup
./y/.snapshot
./x/setup
./x/.snapshot
./z/setup
./z/.snapshot
./c/setup
./c/.snapshot
./b/setup
./b/.snapshot
./a/setup
./a/.snapshot
Tried reversing .snapshot and setup in your example and got the same results.

shivaa 01-17-2014 12:37 AM

Quote:

Originally Posted by sharky (Post 5099407)
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".

sharky 01-17-2014 11:29 AM

Quote:

Originally Posted by shivaa (Post 5099549)
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.

I'll let you know how it turns out.

Thanks,


All times are GMT -5. The time now is 05:56 PM.