How to find file that contains a specific word in Linux and Unix.

The find and grep command is very handy when searching for files that contains a specific word. Both the find and grep commands are universal in Linux and Unix and the syntax is very similar.

Below is an example.

find /home/andrew -type f -exec grep -H ‘networks’ {} \;

This will display all files in the directory /home/andrew that contains the word networks abd output it to screen.

Here is another example using the grep command alone.

grep -r “networks” /home/andrew

About Andrew Lin

Hi, I have always wanted to creat a blog site but never had the time. I have been working in Information Technology for over 15 years. I specialize mainly in networks and server technologies and dabble a little with the programming aspects. Andrew Lin

View all posts by Andrew Lin →