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 07-11-2012
Registered User
 
Join Date: Mar 2010
Posts: 286
Thanks: 11
Thanked 34 Times in 32 Posts
Help with the find cmd

Hello,
I'm having a trouble with the find cmd.
I would like to find all the java versions on my systems.
I have solaris 9 & 10 RHEL and SUSIE.


Code:
java -version

doesn't give all the versions on the server.

So I am trying to use the find command to find them all

Code:
find / -name java

I would like to exclude some directories such as Solaris zones, /tmp and mounted files systems. I don't need directories, I just what the files.

Can someone help me out?
Sponsored Links
    #2  
Old 07-11-2012
bartus11's Avatar
Registered User
 
Join Date: Apr 2009
Posts: 3,139
Thanks: 3
Thanked 954 Times in 933 Posts
To find just regular files:
Code:
find / -name java -type f

Sponsored Links
    #3  
Old 07-11-2012
Registered User
 
Join Date: Mar 2010
Posts: 286
Thanks: 11
Thanked 34 Times in 32 Posts
Thanks for the info.
I tried the command you gave me and it worked great. Is there a way though to exclude a directory, like for example /export/zones?
    #4  
Old 07-11-2012
...@...
 
Join Date: Feb 2004
Location: NM
Posts: 9,646
Thanks: 164
Thanked 641 Times in 618 Posts
two ways:

Code:
find / -name java -type f | grep -v '^/export/zones'
# another way
find / \( -name java -a ! -name '/export/zones/*' \)  -type f

I prefer the grep approach.
Sponsored Links
    #5  
Old 07-11-2012
alister alister is offline Forum Advisor  
Registered User
 
Join Date: Dec 2009
Posts: 2,593
Thanks: 122
Thanked 716 Times in 599 Posts
Quote:
Originally Posted by jim mcnamara View Post
two ways:

Code:
find / -name java -type f | grep -v '^/export/zones'
# another way
find / \( -name java -a ! -name '/export/zones/*' \)  -type f

I prefer the grep approach.
Because it's more readable?

It looks to me as though your find command won't work. The -name primary only handles basenames. There will never be a forward slash in a basename so ! -name '/export/zones/*' will always evaluate true.

The following should do it (untested):

Code:
find / -type f -name java -print -o \( -path /export/zones -prune \)

Regards,
Alister

---------- Post updated at 02:12 PM ---------- Previous update was at 02:07 PM ----------

Quote:
Originally Posted by bitlord View Post
Thanks for the info.
I tried the command you gave me and it worked great. Is there a way though to exclude a directory, like for example /export/zones?
To exclude N directories (untested):

Code:
find / -type f -name java -print     \
       -o \( -path /dir1 -prune \)   \
       -o \( -path /dir2 -prune \)   \
       -o \( -path /dir3 -prune \)   \
...
       -o \( -path /dirN -prune \)

Regards,
Alister
Sponsored Links
    #6  
Old 07-11-2012
Scott's Avatar
Scott Scott is online now Forum Staff  
Administrator
 
Join Date: Jun 2009
Location: Zürich
Posts: 6,858
Thanks: 212
Thanked 745 Times in 651 Posts
All those -o's is also why I prefer the grep (-E) option
Sponsored Links
    #7  
Old 07-11-2012
Registered User
 
Join Date: Mar 2010
Posts: 286
Thanks: 11
Thanked 34 Times in 32 Posts
jim mcnamara,
I was able to get your example to work on both Solaris and RHEL,thanks.

Code:
find / -name java -type f | grep -v '^/export/zones'

alister,
Your examples didn't work on Solaris but worked on RHEL.

Code:
find / -type f -name java -print -o \( -path /tmp -prune \)

I got this error in Solaris

Code:
find: bad option -path
find: path-list predicate-list

Thanks for the help everyone. Sorry I was so late getting back to you, sooner, I had to step away from my desk.
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
Find Failing on directory with spaces in directory name Find xargs sed errors. Find and replace. sipeki UNIX for Dummies Questions & Answers 28 04-08-2012 05:35 PM
find: missing argument to `-exec' while redirecting using find in perl ramkumarselvam Shell Programming and Scripting 2 12-16-2011 06:48 PM
Simplified find command to find multiple file types vickramshetty Linux 2 05-28-2010 01:28 PM
how to find a file named vijay in a directory using find command amirthraj_12 UNIX for Dummies Questions & Answers 6 10-25-2008 12:37 PM
command find returned bash: /usr/bin/find: Argument list too long yacsil Shell Programming and Scripting 1 12-15-2003 05:38 PM



All times are GMT -4. The time now is 12:50 AM.