LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 01-16-2014, 05:00 PM   #1
sharky
Member
 
Registered: Oct 2002
Posts: 488

Rep: Reputation: 54
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.

Last edited by sharky; 01-16-2014 at 05:01 PM.
 
Old 01-16-2014, 05:17 PM   #2
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,977
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
What have you tied so far?

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

--C
 
Old 01-16-2014, 05:29 PM   #3
sharky
Member
 
Registered: Oct 2002
Posts: 488

Original Poster
Rep: Reputation: 54
Quote:
Originally Posted by custangro View Post
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
 
Old 01-16-2014, 06:07 PM   #4
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,977
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
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
 
Old 01-17-2014, 12:23 AM   #5
sharky
Member
 
Registered: Oct 2002
Posts: 488

Original Poster
Rep: Reputation: 54
Quote:
Originally Posted by custangro View Post
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.
 
Old 01-17-2014, 12:37 AM   #6
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Originally Posted by sharky View Post
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".
 
1 members found this post helpful.
Old 01-17-2014, 11:29 AM   #7
sharky
Member
 
Registered: Oct 2002
Posts: 488

Original Poster
Rep: Reputation: 54
Quote:
Originally Posted by shivaa View Post
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,
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Permission on specific Directory / File to specific group AbidDhanaiser Linux - Desktop 1 08-28-2013 03:38 AM
Filename completion in a specific directory for a specific command using tcsh Leo Simon Linux - Software 3 12-29-2012 10:44 AM
Create a directory named like his Parent Directory sina_saeedi82 Linux - Newbie 8 05-26-2011 11:36 AM
using tar to compress specific files in a directory named a certain way slinky66 Linux - Newbie 3 11-25-2009 01:31 PM
shell script: delete all directories named directory.# except directory.N brian0918 Programming 3 07-13-2005 06:54 PM


All times are GMT -5. The time now is 02:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration