Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Here is what I do

tree -R /Applications/NetBeans/NetBeans\ 7.0.app/ | perl -e 'while (<>) { print if /java$/ }'

but of course this doesn't return the result I want.

What I want is to display an executable java file along with its recursive directory so that I would know where that java file is. Something like this structure below

`-- Contents
    `-- Resources
        `-- NetBeans
            `-- ExecutableJavaEnv
                `-- java

This question is inspired from my question on SU. The structure display above actually is not really important because I'm not sure if I can get what I want using find. What I need is just get the path so that I can set my TextMate to run NetBeans' Java instead of /usr/bin/java from my Mac OS X 10.5.8. Advice? Help?

1st Edit:

Thanks for answers so far, I appreciate it. Here is the result of the command I tried:

. find /Applications/NetBeans/NetBeans\ 7.0.app/ -name java
/Applications/NetBeans/NetBeans 7.0.app//Contents/Resources/NetBeans/java
. ll /Applications/NetBeans/NetBeans\ 7.0.app/Contents/Resources/NetBeans/
total 632
-rw-rw-r--   1 arie  admin   6.6K Apr  8 09:29 CREDITS.html
-rw-rw-r--   1 arie  admin   1.7K Apr  8 09:29 DISTRIBUTION.txt
-rw-rw-r--   1 arie  admin   2.1K Apr  8 09:30 LEGALNOTICE.txt
-rw-rw-r--   1 arie  admin    78K Apr  8 09:30 LICENSE.txt
-rw-rw-r--   1 arie  admin   5.4K Apr  8 09:30 README.html
-rw-rw-r--   1 arie  admin   158K Apr  8 09:30 THIRDPARTYLICENSE.txt
drwxrwxr-x   8 arie  admin   272B Apr  8 09:29 apisupport/
drwxrwxr-x   3 arie  admin   102B Apr  8 10:32 bin/
drwxrwxr-x   9 arie  admin   306B Jul  1 15:56 cnd/
drwxrwxr-x   9 arie  admin   306B Apr  8 09:29 dlight/
drwxrwxr-x   9 arie  admin   306B Apr  8 09:30 enterprise/
drwxrwxr-x   6 arie  admin   204B Apr  8 09:30 ergonomics/
drwxrwxr-x   6 arie  admin   204B Jun 11 22:17 etc/
drwxrwxr-x   7 arie  admin   238B Apr  8 09:30 groovy/
drwxrwxr-x  21 arie  admin   714B Jun 11 22:15 harness/
drwxrwxr-x  11 arie  admin   374B Jun 11 22:25 ide/
drwxrwxr-x  12 arie  admin   408B Jul  1 15:56 java/
drwxrwxr-x  10 arie  admin   340B Apr  8 10:15 mobility/
-rw-rw-r--   1 arie  admin    33K Apr  8 09:30 moduleCluster.properties
drwxrwxr-x  15 arie  admin   510B Jun 11 22:17 nb/
-rw-rw-r--   1 arie  admin    15K Apr  8 09:30 netbeans.css
drwxrwxr-x  11 arie  admin   374B Apr  8 09:30 php/
drwxrwxr-x  11 arie  admin   374B Jun 11 22:25 platform/
drwxrwxr-x  10 arie  admin   340B Apr  8 09:30 profiler/
drwxrwxr-x   3 arie  admin   102B Apr  8 08:43 ruby/
drwxrwxr-x   7 arie  admin   238B Apr  8 09:30 websvccommon/
. 

And for another answer is this

. find /Applications/NetBeans/NetBeans\ 7.0.app -type f -executable -name java
find: -executable: unknown option
share|improve this question
    
I don't understand your question. Are you looking for a file called java somewhere under a directory on your system? Are you looking for a file called java anywhere on your system? Are you trying to parse the output of tree, to extract only the parts that are the steps to a file called java? Something else? –  Gilles Jul 23 '11 at 12:03
    
@Gilles, Thanks for your response. Right, I'm looking for a file called java with its complete absolute path somewhere under /Applications/NetBeans/NetBeans\ 7.0.app dir. I apologize for the confusion. –  Arie Jul 23 '11 at 12:09
add comment

3 Answers

up vote 4 down vote accepted

To find executable files called java under the specified directory:

find '/Applications/NetBeans/NetBeans 7.0.app/' -name java -type f -perm -u+x

The output will be one file name per line, e.g.

/Applications/NetBeans/NetBeans 7.0.app/Contents/Resources/NetBeans/ExecutableJavaEnv/java

If you want to omit the …/NetBeans 7.0.app part, first switch to the directory and run find on the current directory (.). There'll still be a ./ prefix.

cd '/Applications/NetBeans/NetBeans 7.0.app/'
find . -name java -type f -perm -u+x

Strictly speaking, -perm u+x selects all files that are executable by their owner, not all files that you can execute. GNU find has a -executable option to look for files that you have execute permission on, taking all file modes and ACLs into account, but this option isn't available on other systems such as OSX. In practice, this is unlikely to matter; in fact for your use case you can forget about permissions altogether and just match -name java -type f.

-type f selects only regular files, not directories or symbolic links. If you want to include symbolic links to regular files in the search, add the -L option to find (immediately after the find command, before the name of the directory to search).

share|improve this answer
    
I marked this answer as accepted because the solution works for another case, ex. find /opt/experiment/ruby/ -name ruby -type f -perm -u+x gives me this /opt/experiment/ruby//bin/ruby. For java file I'm looking for in NB env I updated my question on SU hopefully someone familiar with NetBeans and Java will come up. Thanks guys, all of you, wishing I could upvote, your answers all have been enlightening my day. –  Arie Jul 23 '11 at 12:56
add comment

I think this is what you want:

find /Applications/NetBeans/NetBeans\ 7.0.app -type f -executable -name java
share|improve this answer
    
yep, with type and executable checks it's better –  rvs Jul 23 '11 at 12:09
    
@alex, why is it not working? :-/ . find /Applications/NetBeans/NetBeans\ 7.0.app -type f -executable -name java find: -executable: unknown option Should I change the options after find? But it's still error. –  Arie Jul 23 '11 at 12:17
1  
@ArieKeren -executable is specific to GNU find. In your case, just leave it out. –  Gilles Jul 23 '11 at 12:33
add comment

It seems it can be easily done with find: find /path/ -name java. (Why haven't you tried).

share|improve this answer
    
I tried that, but that didn't work. It gave me a dir called java, not a file. –  Arie Jul 23 '11 at 12:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.