Why doesn't grep -r also look in subdirectories when I search with a glob? [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
6
down vote

favorite
2













This question already has an answer here:



  • What does the asterisk (*) do in grep -nri “searchString” *?

    1 answer



  • How to use “grep” command to find text including subdirectories

    11 answers



Grep with -r was not working for me.



I then made a test situation. The directory /home/den/backup now contains a file with the word washer in it. I also made a subdirectory within /home/den/backup. In that directory a file contains the word washer. The following should return two hits at /home/den/backup/great.txt and /home/den/backup/aaa/info.txt



If I issue



grep -r "washer" /home/den/backup/*.*


the result is one hit.



If I issue



grep -r "washer" /home/den/backup/aaa/*.*


the result is one hit.



Shouldn't the first one have also found the second one, which is in one if its sub-directories?







share|improve this question














marked as duplicate by Sergiy Kolodyazhnyy, muru, karel, Zanna command-line
Users with the  command-line badge can single-handedly close command-line questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Sep 7 at 8:52


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Also see: askubuntu.com/a/1028732/158442
    – muru
    Sep 7 at 2:46










  • *.* looks Windows-style. I prefer find . -type f -name '*' -exec grep 'washer' + because grep -r is prone not to do what you want: Either it does not recurse (because directories are usually not named like *.txt) or it throws errors because directories not being regular files.
    – rexkogitans
    Sep 7 at 6:11







  • 1




    @Zanna with the updated title, looks more like a dupe of the post I linked to.
    – muru
    Sep 7 at 7:39










  • @muru so it does :D
    – Zanna
    Sep 7 at 8:53














up vote
6
down vote

favorite
2













This question already has an answer here:



  • What does the asterisk (*) do in grep -nri “searchString” *?

    1 answer



  • How to use “grep” command to find text including subdirectories

    11 answers



Grep with -r was not working for me.



I then made a test situation. The directory /home/den/backup now contains a file with the word washer in it. I also made a subdirectory within /home/den/backup. In that directory a file contains the word washer. The following should return two hits at /home/den/backup/great.txt and /home/den/backup/aaa/info.txt



If I issue



grep -r "washer" /home/den/backup/*.*


the result is one hit.



If I issue



grep -r "washer" /home/den/backup/aaa/*.*


the result is one hit.



Shouldn't the first one have also found the second one, which is in one if its sub-directories?







share|improve this question














marked as duplicate by Sergiy Kolodyazhnyy, muru, karel, Zanna command-line
Users with the  command-line badge can single-handedly close command-line questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Sep 7 at 8:52


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Also see: askubuntu.com/a/1028732/158442
    – muru
    Sep 7 at 2:46










  • *.* looks Windows-style. I prefer find . -type f -name '*' -exec grep 'washer' + because grep -r is prone not to do what you want: Either it does not recurse (because directories are usually not named like *.txt) or it throws errors because directories not being regular files.
    – rexkogitans
    Sep 7 at 6:11







  • 1




    @Zanna with the updated title, looks more like a dupe of the post I linked to.
    – muru
    Sep 7 at 7:39










  • @muru so it does :D
    – Zanna
    Sep 7 at 8:53












up vote
6
down vote

favorite
2









up vote
6
down vote

favorite
2






2






This question already has an answer here:



  • What does the asterisk (*) do in grep -nri “searchString” *?

    1 answer



  • How to use “grep” command to find text including subdirectories

    11 answers



Grep with -r was not working for me.



I then made a test situation. The directory /home/den/backup now contains a file with the word washer in it. I also made a subdirectory within /home/den/backup. In that directory a file contains the word washer. The following should return two hits at /home/den/backup/great.txt and /home/den/backup/aaa/info.txt



If I issue



grep -r "washer" /home/den/backup/*.*


the result is one hit.



If I issue



grep -r "washer" /home/den/backup/aaa/*.*


the result is one hit.



Shouldn't the first one have also found the second one, which is in one if its sub-directories?







share|improve this question















This question already has an answer here:



  • What does the asterisk (*) do in grep -nri “searchString” *?

    1 answer



  • How to use “grep” command to find text including subdirectories

    11 answers



Grep with -r was not working for me.



I then made a test situation. The directory /home/den/backup now contains a file with the word washer in it. I also made a subdirectory within /home/den/backup. In that directory a file contains the word washer. The following should return two hits at /home/den/backup/great.txt and /home/den/backup/aaa/info.txt



If I issue



grep -r "washer" /home/den/backup/*.*


the result is one hit.



If I issue



grep -r "washer" /home/den/backup/aaa/*.*


the result is one hit.



Shouldn't the first one have also found the second one, which is in one if its sub-directories?





This question already has an answer here:



  • What does the asterisk (*) do in grep -nri “searchString” *?

    1 answer



  • How to use “grep” command to find text including subdirectories

    11 answers









share|improve this question













share|improve this question




share|improve this question








edited Sep 7 at 7:11









Zanna

48k13119227




48k13119227










asked Sep 6 at 22:32









user628388

8317




8317




marked as duplicate by Sergiy Kolodyazhnyy, muru, karel, Zanna command-line
Users with the  command-line badge can single-handedly close command-line questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Sep 7 at 8:52


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Sergiy Kolodyazhnyy, muru, karel, Zanna command-line
Users with the  command-line badge can single-handedly close command-line questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Sep 7 at 8:52


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • Also see: askubuntu.com/a/1028732/158442
    – muru
    Sep 7 at 2:46










  • *.* looks Windows-style. I prefer find . -type f -name '*' -exec grep 'washer' + because grep -r is prone not to do what you want: Either it does not recurse (because directories are usually not named like *.txt) or it throws errors because directories not being regular files.
    – rexkogitans
    Sep 7 at 6:11







  • 1




    @Zanna with the updated title, looks more like a dupe of the post I linked to.
    – muru
    Sep 7 at 7:39










  • @muru so it does :D
    – Zanna
    Sep 7 at 8:53
















  • Also see: askubuntu.com/a/1028732/158442
    – muru
    Sep 7 at 2:46










  • *.* looks Windows-style. I prefer find . -type f -name '*' -exec grep 'washer' + because grep -r is prone not to do what you want: Either it does not recurse (because directories are usually not named like *.txt) or it throws errors because directories not being regular files.
    – rexkogitans
    Sep 7 at 6:11







  • 1




    @Zanna with the updated title, looks more like a dupe of the post I linked to.
    – muru
    Sep 7 at 7:39










  • @muru so it does :D
    – Zanna
    Sep 7 at 8:53















Also see: askubuntu.com/a/1028732/158442
– muru
Sep 7 at 2:46




Also see: askubuntu.com/a/1028732/158442
– muru
Sep 7 at 2:46












*.* looks Windows-style. I prefer find . -type f -name '*' -exec grep 'washer' + because grep -r is prone not to do what you want: Either it does not recurse (because directories are usually not named like *.txt) or it throws errors because directories not being regular files.
– rexkogitans
Sep 7 at 6:11





*.* looks Windows-style. I prefer find . -type f -name '*' -exec grep 'washer' + because grep -r is prone not to do what you want: Either it does not recurse (because directories are usually not named like *.txt) or it throws errors because directories not being regular files.
– rexkogitans
Sep 7 at 6:11





1




1




@Zanna with the updated title, looks more like a dupe of the post I linked to.
– muru
Sep 7 at 7:39




@Zanna with the updated title, looks more like a dupe of the post I linked to.
– muru
Sep 7 at 7:39












@muru so it does :D
– Zanna
Sep 7 at 8:53




@muru so it does :D
– Zanna
Sep 7 at 8:53










1 Answer
1






active

oldest

votes

















up vote
15
down vote



accepted










You can see what's happening here by setting the shell into debug mode using set -x



$ set -x
$ grep -r "washer" /home/steeldriver/backup/*.*
+ grep --color=auto -r washer /home/steeldriver/backup/great.txt
washer


i.e. the shell is expanding *.* and matching the single file great.txt - so grep searches that single file.



If you want to recursively search the whole directory, just give the directory as the argument:



$ grep -r "washer" /home/steeldriver/backup/
+ grep --color=auto -r washer /home/steeldriver/backup/
/home/steeldriver/backup/aaa/info.txt:washer
/home/steeldriver/backup/great.txt:washer


(You can turn debug mode off again using set +x)






share|improve this answer



























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    15
    down vote



    accepted










    You can see what's happening here by setting the shell into debug mode using set -x



    $ set -x
    $ grep -r "washer" /home/steeldriver/backup/*.*
    + grep --color=auto -r washer /home/steeldriver/backup/great.txt
    washer


    i.e. the shell is expanding *.* and matching the single file great.txt - so grep searches that single file.



    If you want to recursively search the whole directory, just give the directory as the argument:



    $ grep -r "washer" /home/steeldriver/backup/
    + grep --color=auto -r washer /home/steeldriver/backup/
    /home/steeldriver/backup/aaa/info.txt:washer
    /home/steeldriver/backup/great.txt:washer


    (You can turn debug mode off again using set +x)






    share|improve this answer
























      up vote
      15
      down vote



      accepted










      You can see what's happening here by setting the shell into debug mode using set -x



      $ set -x
      $ grep -r "washer" /home/steeldriver/backup/*.*
      + grep --color=auto -r washer /home/steeldriver/backup/great.txt
      washer


      i.e. the shell is expanding *.* and matching the single file great.txt - so grep searches that single file.



      If you want to recursively search the whole directory, just give the directory as the argument:



      $ grep -r "washer" /home/steeldriver/backup/
      + grep --color=auto -r washer /home/steeldriver/backup/
      /home/steeldriver/backup/aaa/info.txt:washer
      /home/steeldriver/backup/great.txt:washer


      (You can turn debug mode off again using set +x)






      share|improve this answer






















        up vote
        15
        down vote



        accepted







        up vote
        15
        down vote



        accepted






        You can see what's happening here by setting the shell into debug mode using set -x



        $ set -x
        $ grep -r "washer" /home/steeldriver/backup/*.*
        + grep --color=auto -r washer /home/steeldriver/backup/great.txt
        washer


        i.e. the shell is expanding *.* and matching the single file great.txt - so grep searches that single file.



        If you want to recursively search the whole directory, just give the directory as the argument:



        $ grep -r "washer" /home/steeldriver/backup/
        + grep --color=auto -r washer /home/steeldriver/backup/
        /home/steeldriver/backup/aaa/info.txt:washer
        /home/steeldriver/backup/great.txt:washer


        (You can turn debug mode off again using set +x)






        share|improve this answer












        You can see what's happening here by setting the shell into debug mode using set -x



        $ set -x
        $ grep -r "washer" /home/steeldriver/backup/*.*
        + grep --color=auto -r washer /home/steeldriver/backup/great.txt
        washer


        i.e. the shell is expanding *.* and matching the single file great.txt - so grep searches that single file.



        If you want to recursively search the whole directory, just give the directory as the argument:



        $ grep -r "washer" /home/steeldriver/backup/
        + grep --color=auto -r washer /home/steeldriver/backup/
        /home/steeldriver/backup/aaa/info.txt:washer
        /home/steeldriver/backup/great.txt:washer


        (You can turn debug mode off again using set +x)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Sep 6 at 23:21









        steeldriver

        62.9k1197165




        62.9k1197165












            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            Installing NextGIS Connect into QGIS 3?

            One-line joke