Find the answer to your Linux question:
Results 1 to 5 of 5
Hello, I would like to search inside a folder and its sub-folders for the name of a file that contains a specific text string. What command should I run? Thanks, ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2004
    Posts
    11

    Search file containing text


    Hello,

    I would like to search inside a folder and its sub-folders for the name of a file that contains a specific text string.

    What command should I run?

    Thanks,

    David

  2. #2
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,729
    Code:
    find -iname <string>
    find -iname *hello*
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  3. #3
    Just Joined!
    Join Date
    Oct 2004
    Posts
    11

    String inside a file

    Hi,

    I didn't explain myself correctly. I don't want to find a "file name" that includes a string but rather the "name of a file" where the "file itself contains a string".

    Thanks,

    David

  4. #4
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,729
    Code:
    grep 'abc' -r *
    It will fine string abc in all files in folder and subfolders.
    Check manual of grep here. You can use sed for more efficient results but I am not familiar with it.
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  5. #5
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    Not sure how a stream editor can give more efficient results than grep, but in casper's example use grep's -l option to get the names of the files containing the wanted string, rather than every matching line.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •