Skip to main content
3 of 14
add a note
hornetbzz
  • 9.4k
  • 6
  • 41
  • 58

FIND excluding directories foo and bar :

find /dir \( -name foo -prune \) -o \( -name bar -prune \) -o -name "*.sh" -print 

GREP -R:
you know already

Combine FIND and GREP :

find /dir \( -name node_modules -prune \) -o -name "*.sh" -exec grep --color -Hn "your text to find" {} 2>/dev/null \; 

Ag

If you frequently search through code, Ag (The Silver Searcher) is a much faster alternative to grep, that's customized for searching code. For instance, it automatically ignores files and directories listed in .gitignore, so you don't have to keep passing the same cumbersome exclude options to grep or find.

Note: the purpose if this answer is not to browse GREP possiblities but to show a portable solution : shold also work with busybox or GNU version older than 2.5.

hornetbzz
  • 9.4k
  • 6
  • 41
  • 58