grep -r will not search subdirectories

Asked by Robert T McQuaid

grep -r Esther *.htm

Typing the above command when positioned in a directory containing
.htm files with the requested text produces a few lines of output.
When changing to the next outer directory with cd .. the same
command produces no output. It will not look at subdirectories.

Ubuntu release 12.10
version grep 12.12-2

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu grep Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:

This question was originally filed as bug #1134307.

Revision history for this message
Robert T McQuaid (rtmq) said :
#1

grep -r Esther *.htm

Typing the above command when positioned in a directory containing
.htm files with the requested text produces a few lines of output.
When changing to the next outer directory with cd .. the same
command produces no output. It will not look at subdirectories.

Ubuntu release 12.10
version grep 12.12-2

Revision history for this message
Ralph Corderoy (ralph-inputplus) said :
#2

grep -r Esther .
That will fair better.
Don't have time to explain.
The shell is expanding *.htm and grep is seeing the results.
It is then recursing into each if they are a directory or just reading them if they're are a file.
find -name '*.htm' -exec grep Esther {} +
is probably what you're trying to do; search for Esther through all *.htm files from here on down.

Can you help with this problem?

Provide an answer of your own, or ask Robert T McQuaid for more information if necessary.

To post a message you must log in.