How to find all files containing specific text in Linux?

Share this article

One of the common commands that I use most frequently in my day-to-day Linux life is for finding files that contains a particular text. Take for an example that I want to search all the files in the current directory that contains string “Hello! this is my file”. The command that is use mostly is this:

find . -type f -exec grep -il 'Hello! this is my file' {} ; 

This search ignores the cases. If you want to search with definite cases (upper or lower) remove the “-i” from grep. You can replace “.” (dot, which means current directory) by the path of the directory in which you want to conduct the search. If you want to search in the whole system then use “/” (it means root directory).

  • Pingback: Use SearchMonkey To Search Text In All Files Within A Directory In Ubuntu()

  • Nikhil Maggu

    Another way possible

    grep -Pri ‘TEXT TO SEARCH’ /

    ex: grep -Pri ‘hello world’ /root/

    • Nikhil Maggu

      Correction (in example):-

      grep -Pri ‘hello world’ /root/

  • Shoaib Jameel

    To be very frank, I was just looking for this one :)

    • http://computerandu.wordpress.com Abhishek Prakash Chaturvedi

      Sharm nahi aa rahi hai shoaib…4 years of computer science…3 years of phd …aur ye khoj rahe ho net pe… 😛 😛