Friday, December 21, 2012

Linux Commands Help: grep

Find text in a file:

 For example to find out "404" requests( page not found ) in apache log file:

grep "404" /var/log/apache2/access.log
 The above command displays all the entries contains the word "404".
   

grep -n "404" /var/log/apache2/access.log
The above command displays all the entries contains the word "404" with line numbers.
   

grep -c "404" /var/log/apache2/access.log
The above command displays the no. of entries contains the word "404"

grep -c "404\|192.168.20.32" /var/log/apache2/access.log
The above command displays the no. of entries contains both the words "404" and "192.168.20.32"


No comments:

Post a Comment