Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How do I recursively grep all directories and subdirectories?  (Read 85512 times)

0 Members and 1 Guest are viewing this topic.

balasahu

    Topic Starter


    Starter

    • Edumotivation
  • Experience: Expert
  • OS: Linux variant

How do I recursively grep all directories and subdirectories?

Code: [Select]
find . | xargs grep "texthere" *
Thanks.

nil

  • Global Moderator


  • Intermediate
  • Thanked: 15
    • Experience: Experienced
    • OS: Linux variant
    Re: How do I recursively grep all directories and subdirectories?
    « Reply #1 on: May 04, 2021, 03:26:12 PM »
    No need for xargs - you can use the grep -r option:

    Code: [Select]
    me@nil:~/mydir$ find .
    .
    ./dir4
    ./dir2
    ./dir2/file-b.txt
    ./dir2/dir3
    ./dir2/dir3/file.txt
    me@nil:~/mydir$ grep -r Lorem .
    ./dir2/file-b.txt:Lorem ipsum dolor amet
    ./dir2/dir3/file.txt:Lorem ipsum

    If you want to follow symlinks, use -R instead.

    Examples at Computer Hope - https://www.computerhope.com/unix/ugrep.htm#examples
    Do not communicate by sharing memory; instead, share memory by communicating.

    --Effective Go