Find if content exists in some file ¶
Simple Search¶
Lets say we have to sarch if pluign exists in ~/.bashrc
file, then we can use
grep -r plugin ~/.bashrc
the output is
output
/Users/amar/.bashrc:# Which plugins would you like to load? (plugins can be found in ~/.oh-my-bash/plugins/*)
/Users/amar/.bashrc:# Custom plugins may be added to ~/.oh-my-bash/custom/plugins/
Recursive Search¶
grep -R "domain" /etc/apache2/httpd.conf
# (1)
/etc/apache2/httpd.conf:# as error documents. e.g. admin@your-domain.com
- Output of the grep command
Finding exact text¶
Lets imagine we have a file named file.txt
with below contents
File contents
$ cat file.txt
Ottawa
is
an
awesome
place
places
to
too
live
Below will find all words which have to
Simple search
$ grep to file.txt
to
too
Finding the exact to
Find exact text
$grep -w to file.txt
to