Grep with AND

You can use grep to search for any line from any file in the current path that contains one word and another word. Here's how.

grep -Ers 'cpage.*gallery' ./

This uses the -E command line argument to indicate that our search string is a regular expression. Then, we can use “.*” to indicate look for everything. As a result, the above example will look for any line that includes the string 'cpage' followed by anything and then followed by 'gallery'. The -r switch makes it recursive and the -s switch makes it suppress errors such as 'No file or directory.'

comments powered by Disqus
linux/grep_with_and.txt · Last modified: 2020/06/01 22:53 (external edit)