Tips&Tricks

How to find a text in files on Linux / Unix in terminal

files

You may think, that you should use the “find” utility to … find. But you need the “grep”.

grep -rnw '/path/to/directory/' -e 'pattern'

Where

-r is recursive (-R for using symbolic links),
-n is line number,
-w stands for match the whole word.

And it’s pretty common – grep is perfect for searching something in files. And you can use find if you looking for file (not a content).

Also, there is many ways to do it. But if you remember this snippet, you’ll can search on all Unix-like systems.