Linx Grep Command Search Find Identify Word File Directory


Using grep command we can search Find Identify the Particular word In Give Input file .Find Identify SSL word in the /etc/httpd/conf file

[root@bashscriptconf]# grep SSL /etc/httpd/conf/httpd.conf
# SSL protocol.
Find & Identify the ssl word But word ssl is Small Letter
[root@bashscriptconf]# grep ssl /etc/httpd/conf/httpd.conf
# (e.g. :80) if mod_ssl is being used, due to the nature of the

Using -i it will Ignore The Case Sensitive
[root@bashscriptconf]# grep -i ssl /etc/httpd/conf/httpd.conf
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
So it will Display the Line which are has the word ssl.Both small and Cabs Letter

--color display the search result with color Output
-n display the Line Number
[root@bashscript etc]# grep --color -n option dhcpd.conf
7: option routers;
8: option subnet-mask;
10: option nis-domain "";
11: option domain-name "";
12: option domain-name-servers;
14: option time-offset -18000; # Eastern Standard Time
15:# option ntp-servers;
16:# option netbios-name-servers;
19:# option netbios-node-type 2;

Linux Grep command search the two string words
From httpd.conf file it will filter line which is word matching html word. From this output it will display the line which are contain the number 403 and 506.
[root@nagm conf]#cat httpd.conf | grep html | egrep '403|506'
# ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var
# ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var

Search The Word In Directory | Example Trick and Tips
-r it is search find the word Directory recursive
Find the word John in the /etc Directory
[root@bashscriptconf]# grep -r john /etc/*
/etc/httpd/conf/ronald:Hi this is john
/etc/httpd/conf/ronald:johnronald is a good boy

In the Ordinary search it will display word which are have hosts
[root@localhost conf]# grep hosts /etc/httpd/conf/httpd.conf
#     of all virtual hosts.
# hosts/>
-w option Display Word With Exact Search word
-w option it will display the line which are have exact word hosts so vhosts emove from the output
[root@bashscript conf]# grep -w hosts /etc/httpd/conf/httpd.conf
# of all virtual hosts.

-v Invert Match Reverse Of The Ordinary Search.
It will display the line which are doesn't have word hosts
[root@bashscript conf]# grep -v hosts /etc/httpd/conf/httpd.conf
# The location and format of the access logfile (Common Logfile Format).
# If you do not define any access logfiles within a
# container, they will be logged here. Contrariwise, if you *do*

Command Output In grep
[root@bashscript ~]# getconf -a | grep "LONG_BIT"
While in the getconf -a it will display the all the Configuration values.
getconf "LONG_BIT" it will filter the word and display it

Count The No Of Occurrence Option -c
[root@localhost conf]# grep -c option httpd.conf
Command Ticks and Tips
#ls -d /proc/* | grep [0-5]   //List Process with 0 and 5
#grep -o "ing ar" install.log  // Match  Particular Pattern.
#grep -o "ing.*ar" install.log

No comments:
Write comments