If you are a Linux beginner, VnTutor think that the first question which you will ask VnTutor is that what is grep in the title of this post. Linux Command Line can answer this question.

whatis grep
grep (1) - print lines matching a pattern

and ...
man grep

Grep is a command line tool that allows you to find a string in a file or stream. It is simple to use this command.
grep keyword filename

But the true power of grep come from its various options and the way which you use it in different situations. In this post, VnTutor will show you a list of 10 tips to work with this command more effectively.

1. find all files in your home directory that contains a given keyword
grep -r keyword $HOME

2. find all files in the current working directory that contains a given keyword
grep -r keyword .

3. print out three lines after matching
grep -A 3 keyword yourfile

4. print out five lines before matching
grep -B 5 keyword yourfile

5. show the line number where the keyword is matched
grep -n keyword yourfile

6. find all files which are updated locally from CVS
cvs status | grep -A 3 Modified

7. find all files HTML such that the path must be matched the keyword firefox
locate *.html | grep firefox

8. print information of one of the current running processes, like firefox
ps aux | grep firefox

9. display to standart out put the content of file .bashrc without comments
cat .bashrc | grep -v '#'

10. what happen in user log file from 11 to 12 am
grep -E "11|12" /var/log/user.log