Solved

grep: *.java: No such file or directory

Posted on 2003-10-28
21
1,292 Views
Last Modified: 2013-11-13
Can anyone tell me why I get this infuriating error message when I issue this command?

grep -rl implements *.java

Surely I don't need to use an additional command?

I'm using GNU grep 2.4.2
0
Comment
Question by:CEHJ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 3
  • +5
21 Comments
 
LVL 5

Expert Comment

by:willy134
ID: 9636889
I believe it is looking for a directory called something.java  why don't you use

grep -rl implements * | grep java

Good Luck
willy
0
 
LVL 1

Expert Comment

by:MJoyce
ID: 9639234

Or try

grep -rl implements *java

presumably you do have some files where the names end in java ?

Matt
0
 
LVL 86

Author Comment

by:CEHJ
ID: 9640679
>>presumably you do have some files where the names end in java ?

Of course ;-) btw I've already tired that (I think). I'll try it again to be sure. Why won't a glob work though?

Don't tell me I really *have* to do something like

grep -rl implements `find . -name *.java`

?
0
Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

 
LVL 86

Author Comment

by:CEHJ
ID: 9640836
willy134 i missed you comment at first

>>grep -rl implements * | grep java

Is something quite different ;-) And I don't want grep looking in all files
0
 
LVL 86

Author Comment

by:CEHJ
ID: 9640902
>>Is something quite different

Let me qualify that. It will have the same *effect* as I'm looking for (although the second re should really be qualified by the line end) but why give the first grep the unnecessary overhead of searching all files?
0
 

Expert Comment

by:jetstream
ID: 9641692
Try
grep -rl implements */*.java
0
 
LVL 86

Author Comment

by:CEHJ
ID: 9641756
That won't cut it - it excludes the current directory
0
 
LVL 20

Expert Comment

by:Gns
ID: 9644471
The problem is _where_ the glob is expanded (and who does the expansion... namely the shell)... As you write it, it'll just expand in "." and include anything (files or directories) ending in .java ... You should be using the --include=<glob> instead:
grep -rl --include=\*.java implements .

-- Glenn
0
 
LVL 20

Expert Comment

by:Gns
ID: 9644506
Ooops, that was for gnu grep version 2.5.1 ... 2.4.2 doesn't have it, so unless you'd fancy an upgrade, the find/grep combo is it.

-- Glenn
0
 
LVL 62

Expert Comment

by:gheist
ID: 9644720
or you can type
set -o noglob
grep with dangerous wildcard*
set +o noglob
0
 
LVL 3

Expert Comment

by:guynumber5764
ID: 9646256
does "ls *.java" give you the same message?

(that might answer your question)

Also, I always keep a few one-line scripts to the effect of:

find / -name "$1" -print 2>/dev/null
and
find / -exec grep "$1" {} \; 2>/dev/null

lying around.  I won't swear to the syntax but you get the idea.
0
 
LVL 3

Expert Comment

by:guynumber5764
ID: 9646294
Ignore the bonehead (ls) part of my prev post and try;

find . -name "*.java" -exec grep implements {} \; -print

it'll get you into the neighbourhood (if the quotes on the -exec are right)
0
 
LVL 20

Expert Comment

by:Gns
ID: 9649436
That "find ... -exec ..." is worse in one respect, and better in one that the "grep ... `find ...`". Worse in the excessive fork/exec, and better sine it avoids any commandline lenght/number of parameters issues. The best on this account would be
find . -name \*.java -print | xargs grep implements
but CEHJ states s/he doesn't want that.... so then the only way would be to upgrade to a gnu grep that will allow the --include= thing (as in 2.5.1).

I think that just officially beat this question to death...:-)

-- Glenn
0
 
LVL 20

Accepted Solution

by:
Gns earned 50 total points
ID: 9649462
"one that the" -> "one than the"
"better sine" -> "better since"
"find . -name \*.java -print | xargs grep implements" -> "find . -name \*.java -print | xargs grep -l implements"

... So many errors in such a short comment... And then one wonders where there are such an abundance of bugs:-)

-- Glenn (a.k.a. Le Grand Typo)
0
 
LVL 86

Author Comment

by:CEHJ
ID: 9649989
>>so unless you'd fancy an upgrade

Would that easy enough to do?
0
 

Expert Comment

by:jetstream
ID: 9649990
This works for me. And it's not long winded.

grep -l implements `find . -name *.java`
0
 
LVL 20

Expert Comment

by:Gns
ID: 9650253
.... And it has already been suggested (as not feasible... by CEHJ... and do read my comment on it's merits/non-merits (implied by the find ... -exec ... comment)) jetstream.

CEHJ: Well, that depends a little on distro etc. You could very well just build it from source (grab it from a gnu-mirror... or ftp://ftp.gnu.org/gnu/grep note that only the source rpm is "there" ATM, since they are confirming that noone has ...manipulated the tar-files. I'd guess 2.5 would be fine too. If youbuild it from source, it is often prudent to install to "an alternate location" than the distros "normal location", or removing the grep package altogether before running make install...
Or you might have an "update" for your distro... If it is rpm-based, http://www.rpmfind.net might be a help... or just apt-get for Debian... As I said, it depends:-).

-- Glenn
0
 
LVL 3

Expert Comment

by:guynumber5764
ID: 9653044
jet & gns... I guess I'll be tweaking my find scripts this aft.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 9673940
didn't read all the comments, so please be patient if my suggestion still have been done:

  grep -rl implements *

or:

  grep -rl implements *|grep java
0
 
LVL 20

Expert Comment

by:Gns
ID: 9676970
> grep -rl implements *
Too "inclusive" ... Not limited to results in .java files;-)

> grep -rl implements *|grep java
The first comment (by willy134) mention this... You're a man by your word Achim, you really didn't read all the comments:-):-)
Nice seeing you active again though;-).

-- Glenn
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 9677091
dooh, the very first comment unread by me, and I've some more daylight hours than Gns ;-)
Skol
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Monitor input from a computer is usually nothing special.  In this instance it prevented anyone from using the computer.  This was a preconfiguration that didn't work.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question