In this tip, we will see how to use the terminal to search inside any type of file under Linux. You can search for text, keywords, strings, etc. By using this command, you will save a lot of time, and you will avoid browsing the content of files manually.

So, launch the terminal and issue this command:

find ./ -name "*.ext" -print | xargs grep "keyword"

In the command given above, you have to change ".ext" with the file extension you are going to search inside, then replace "keyword" with text you want to search.

Here is an example:

find ./ -name "*.php" -print | xargs grep "<? print 'php code'; ?>"

--> This command will search inside the current folder all PHP files for this code: "".

Here is another example:

find ./ -name "*.txt" -print | xargs grep "How to unlock"

--> This command will search all text files under the current folder for this keyword: "How to unlock".

That's it!

Post a Comment