Jak najít soubory obsahující znakový řetězec

Z Znalosti
Verze z 2. 7. 2016, 18:46, kterou vytvořil Admin (diskuse | příspěvky) (Založena nová stránka s textem „Kategorie:Návody Našel jsem návod: [http://stackoverflow.com/questions/16956810/finding-all-files-containing-a-text-string-on-linux Finding all fil…“)
(rozdíl) ← Starší verze | zobrazit aktuální verzi (rozdíl) | Novější verze → (rozdíl)

Našel jsem návod:

Finding all files containing a text string on Linux:

Do the following:

grep -rnw 'directory' -e "pattern"

-r is recursive, -n is line number and -w stands match the whole word. Along with these, --exclude or --include parameter could be used for efficient searching. Something like below:

grep --include=\*.{c,h} -rnw 'directory' -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 'directory' -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, the following shows how to integrate --exclude-dir:

grep --exclude-dir={dir1,dir2,*.dst} -rnw 'directory' -e "pattern"

This works for me very well, to achieve almost the same purpose like yours.