Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • 23
    What's the business with *? It will either result in shell wildcard expansion (if there are filenames matching the wildcard pattern), or grep will take it as 0-or-more repetition operator for the character preceding *.
    – usta
    Commented Mar 27, 2013 at 6:19
  • 10
    Now let's consider both possibilities for grep -nr MobileAppSer* . 1. Assume we have 3 files in the current directory matching MobileAppSer* wildcard pattern: named MobileAppServlet.java, MobileAppServlet.class, MobileAppServlet.txt. Then grep will be invoked like this: grep -nr MobileAppServlet.class MobileAppServlet.java MobileAppServlet.txt .. It means search for text "MobileAppServlet.class" in files MobileAppServlet.java, MobileAppServlet.txt, and elsewhere in the current directory - which surely isn't what the user wants here.
    – usta
    Commented Mar 27, 2013 at 6:30
  • 7
    2. In case there are no files in the current directory matching the MobileAppSer* wildcard pattern, grep will receive the argument MobileAppSer* as-is and thus will take it as search for text "MobileAppSe" followed by 0 or more occurrences of "r", so it will attempt to find texts "MobileAppSe", "MobileAppSer", "MobileAppSerr", "MobileAppSerrr", etc. in current directory's files contents - not what the user wants either.
    – usta
    Commented Mar 27, 2013 at 6:36
  • 5
    This is a dubious choice of regex. Usta has pointed this out. Commented Mar 2, 2014 at 19:24
  • I ran grep -nr 'yourString*' . and got some files with "binary file matches". You can add --text or -a to prevent this: grep -anr 'yourString*' .
    – parsley72
    Commented Sep 30, 2022 at 1:46