Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-15-2012
Registered User
 
Join Date: Jul 2011
Posts: 26
Thanks: 19
Thanked 0 Times in 0 Posts
How to find from / but exclude certain folder?

Hi Unix Specialists,

I need your advice on how to find all the files from root ( / ) filesystem but exclude those from /export/home (different filesystem) folder. Below are some of the find statements that I have tried without success:


Code:
find / -name '/export/home' -prune -o print -ls


Code:
  find / -type d -name '/export/home' -prune -o -ls
  find / -type d -name "\/export\/home" -prune -o –ls 

General searches & man page suggest similar commands but still couldn’t work it out still.

I am running on Solaris 10 x86 platform.

Your assistance would be much appreciated.

Thanks,

George
Sponsored Links
    #2  
Old 06-15-2012
vbe's Avatar
vbe vbe is online now Forum Staff  
Moderator
 
Join Date: Sep 2005
Location: Switzerland - GE
Posts: 4,636
Thanks: 118
Thanked 256 Times in 245 Posts
I dont get you here, what are you looking for?
If /export/home is a separate filesystem, why are you looking for it then?
Sponsored Links
    #3  
Old 06-16-2012
Registered User
 
Join Date: Jul 2011
Posts: 26
Thanks: 19
Thanked 0 Times in 0 Posts
Hi vbe,

I need to search for all the files from / onwards which means that it would also pickup everything on /export /home as well. As a result, I am looking for the right find syntax command to list every single files & folders starting from / (root) filesystem but ignore or bypass /export/home folder which is also a filesystem.

One way to do this is to unmount /export/home before running "find / -ls". However, it is not possible to unmount this filesystem due to opened files & database in a production environment.

Thanks,

George
    #4  
Old 06-16-2012
Lem Lem is offline
Registered User
 
Join Date: Jun 2012
Location: Lombardia, Italy
Posts: 179
Thanks: 5
Thanked 38 Times in 38 Posts
Do not use -name, use -path (I hope it works in Solaris):


Code:
find / -type d -path /export/home -prune -o -ls

Sponsored Links
    #5  
Old 06-16-2012
alister alister is offline Forum Advisor  
Registered User
 
Join Date: Dec 2009
Posts: 2,601
Thanks: 123
Thanked 717 Times in 600 Posts
A workaround for find without -path:

Code:
find / -type d -name home -exec test {} = /export/home \; -prune -o -ls

The -name home expression is not required, but it saves work by preventing -exec test ... when it cannot possibly succeed.

Regards,
Alister

Last edited by alister; 06-16-2012 at 05:28 PM..
Sponsored Links
    #6  
Old 06-16-2012
methyl methyl is offline Forum Staff  
Moderator
 
Join Date: Mar 2008
Posts: 6,388
Thanks: 286
Thanked 668 Times in 640 Posts
Another way. Work from the mounted filesystem list and ignore /export/home .

Code:
#!/bin/ksh
mount | awk '{print $1}' |grep -v "\/export\/home" | sort | while read filesystem
do
     find ${filesystem} -xdev -type f -print
done

The "-type f" is because you mentioned files not directories.
The "sort" is because I like things on order !
The "-xdev" confines the "find" to that filesystem, thus avoiding duplicates caused by links.



Ps. If you actually wanted to only search the root filesystem, the "-xdev" is a big hint.

Last edited by methyl; 06-16-2012 at 06:42 PM.. Reason: mispaste
Sponsored Links
    #7  
Old 06-18-2012
Registered User
 
Join Date: Jul 2011
Posts: 26
Thanks: 19
Thanked 0 Times in 0 Posts
Bug How to find from / but exclude certain folder?

Hi All,

Thanks to all 3 respondent to my queries. Below are the out the outcome from your suggestions:

Quote:
Len wrote:
find / -type d -path /export/home -prune -o -ls
find: bad option -path
find: [-H | -L] path-list predicate-list (Solaris does not support -path syntax)


Quote:
alister wrote:
find / -type d -name home -exec test {} = /export/home \; -prune -o -ls
Brief to the point and works fine and make use of all the functionalities available in find.

Quote:
methyl wrote:
#!/bin/ksh
mount | awk '{print $1}' |grep -v "\/export\/home" | sort | while read filesystem
do
find ${filesystem} -xdev -type f -print
done
Too much scripting which doesn't make use of all the built-in features in find even though it also worked.

The second suggestion is most useful even though it is much appreciated for all your inputs.

Thanks,

George
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
[Solved] Using Find with an exclude/exclude file metallica1973 Ubuntu 2 10-23-2011 10:07 AM
Find command with exclude db2dbac Shell Programming and Scripting 1 05-31-2011 07:35 PM
Exclude a directory in 'find' mutex1 Shell Programming and Scripting 1 12-19-2010 04:50 PM
Find all text files in folder and then copy to a new folder cgkmal Shell Programming and Scripting 4 06-20-2009 01:12 PM
Find but exclude directories tadi18 Shell Programming and Scripting 9 09-12-2008 11:34 AM



All times are GMT -4. The time now is 11:43 AM.