How to search multiple files for a string of text in Linux

Home > Search > How-to
  by

The grep command can be used to search every file in a directory for a string of text. In this example, every file below the opt directory is searched for the text Hello World.

The -Rnw option is the short version of --dereference-recursive, --line-number, and --word-regex. This searches every file below the directory, adds the line number to the output, and only returns results that match the entire word searched.

The -ie option is the short version of --ignore-case and --regexp. This makes sure the search is not case sensitive.

~]# grep -Rnw '/opt' -ie 'hello world'

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments