MyTetra Share
Делитесь знаниями!
Поиск текста по всем файлам в каталоге (рекурсивно)
Время создания: 11.04.2016 14:05
Текстовые метки: grep
Раздел: Linux - Поиск текста
Запись: ivnglkv/mytetra/raw/master/base/1460372718l4xnol5jql/text.html на bitbucket.org

Do the following:

grep -rnw '/path/to/somewhere/' -e "pattern"

  • -r or -R is recursive,
  • -n is line number, and
  • -w stands match the whole word.
  • -l (lower-case L) can be added to just give the file name of matching files.
  • Along with these, --exclude or --include parameter could be used for efficient searching. Something like below:

grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern"

This will only search through the files which have .c or .h extensions. Similarly a sample use of --exclude:

grep --exclude=*.o -rnw '/path/to/somewhere/' -e "pattern"

Above will exclude searching all the files ending with .o extension. Just like exclude file it's possible to exclude/include directories through --exclude-dir and --include-dir parameter; for example, the following shows how to integrate --exclude-dir:

grep --exclude-dir={dir1,dir2,*.dst} -rnw '/path/to/somewhere/' -e "pattern"

 
MyTetra Share v.0.65
Яндекс индекс цитирования