I'm searching for the way to find a file that contains specified string text.

It should be fast as possible but its not that important.

I was reading the manual, and I've build something like that: grep my_string * -r and it works at all, but if there are many directories to search.

Are there any other ways to find a file that contains specified string in FreeBSD?

  • there aren't many ways that could make searching for string faster, than grep. and if you want to search multiple directories, just list them ... grep -r string dir1 dir2 dir3, or just grep the string on the whole drive grep -r string / (this could take a long time though and i'm not sure if freebsd grep will dig into devices by default)
    – Fox
    Jan 11, 2012 at 17:45
  • 2
    @Fox FreeBSD will dig into the devices as well, but will most likely spit out a warning and move on.
    – Tim
    Jan 11, 2012 at 18:24
  • 1
    The -x option will prevent find from descending into directories with device numbers different from the starting point of the find, so devices will be skipped. Jan 15, 2012 at 5:31
  • @RoyceWilliams Good point!
    – Cyclone
    Jan 15, 2012 at 8:29

1 Answer 1


Did you mean:

grep -rl my_search_pattern    my_dir1 my_dir2 my_dir3 my_another_file

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .