Question:how to use grep command unix command line?


Grep is useful when you need to search for content within a file. The following command will search through every file in the current directory and all files in subdirectories and return the line in the file that matches the regular expression. I escape the period to tell grep I want to find a literal period and to not use the dot regular expression metacharacter.

grep -r 'immense\.net' .

Grep and find can work together to search the contents of the files that are found using the find command. The following two commands are different ways to do the same thing: search through all php files looking for the string ‘propel’.

find . -type f -name '*.php' -exec grep 'propel' '{}' \;
find . -type f -name '*.php' | xargs grep 'propel'

If you don’t understand how pipes work you should learn how to use them.

asked Sep 13, 2013 in LINUX by anonymous
edited Sep 12, 2013
0 votes

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.