Grep is an essential Linux and Unix command. It is used to search text and strings in a given file. In other words, grep command searches the given file for lines containing a match to the given strings or words.
The syntax is as follows:
grep 'word' filename fgrep 'word-to-search' file.txt grep 'word' file1 file2 file3 grep 'string1 string2' filename cat otherfile | grep 'something' command | grep 'something' command option1 | grep 'data' grep --color 'data' fileName grep [-options] pattern filename fgrep [-options] words file
You can search recursively i.e. read all files under each directory for a string “192.168.1.5”
$ grep -r "192.168.1.5" /etc/
OR
$ grep -R "192.168.1.5" /etc/
Sample outputs:
/etc/ppp/options:# ms-wins 192.168.1.50 /etc/ppp/options:# ms-wins 192.168.1.51 /etc/NetworkManager/system-connections/Wired connection 1:addresses1=192.168.1.5;24;192.168.1.2;
You will see result for 192.168.1.5 on a separate line preceded by the name of the file (such as /etc/ppp/options) in which it was found. The inclusion of the file names in the output data can be suppressed by using the -h option as follows:
$ grep -h -R "192.168.1.5" /etc/
OR
$ grep -hR "192.168.1.5" /etc/
Sample outputs:
# ms-wins 192.168.1.50 # ms-wins 192.168.1.51 addresses1=192.168.1.5;24;192.168.1.2;
At NexonHost, we believe that everyone deserves to have their services and applications be fast, secure, and always available.
Be the first who gets our daily news and promotions directly on your email.
Copyright © 2025 . All Rights Reserved To NexonHost.