How to search by content on Ubuntu

You need to specify a file when using the grep command. With the command you're using, you're searching in the standard input...

Try grep -r "test" directory.


find / -name "*.txt" -exec grep "text here" {} \; -print 2>/dev/null

Which can be explained in human speak as:

  1. find
  2. starting from /
  3. in all files named *.txt (quotes are to bypass shell interpretation)
  4. with the resulting hits, perform the following
  5. grep "test here"
  6. in the file {}
  7. end of exec (\;) escaped end of statement
  8. print the files that match
  9. redirect error messages in sink (since you might not be root, otherwise just sudo it).