0

I am trying to retrieve the path to a Java class file. I have 2 projects in my eclipse: project_a and project_b. I navigated to project_a's bin folder and tried the command locate WebPerformanceUtil.class. But it gives me four paths:

  1. home/local/prasanth/eclipse/project_a/bin/com/web/utils/WebPerformanceUtil.class
  2. /home/local/prasanth/eclipse/project_a/bin/com/web/utils/ChromeWebPerformanceUtil.class
  3. /home/local/prasanth/eclipse/project_b/bin/com/web/utils/WebPerformanceUtil.class
  4. /home/local/prasanth/eclipse/project_b/bin/com/web/utils/ChromeWebPerformanceUtil.class

But I want only the path which contains the the bin folder of the project which I'm working in.

2 Answers 2

2

You can use find:

find . -type f -name WebPerformanceUtil.class

where . is ~/eclipse/project_folder

1
1

You can use the following command:

locate WebPerformanceUtil.class | grep $(pwd)
  • grep $(pwd) displays only the matches found under your current working directory (/home/local/prasanth/eclipse/project_a/ in your case).

After your edit:

Since you only want the exact filename, you can also use regular expressions with locate. The command is the following:

locate -r '\<WebPerformanceUtil.class\>' | grep $(pwd)
  • The -r parameter tells locate to use regular expressions.
1
  • Hi thank you for your answer. I have a file called ChromeWebPerformanceUtil.class and that too is getting listed, how can I avoid that? Jun 18, 2019 at 10:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .