Find files containing a keyword

snippets
Published

October 21, 2022

Output

Find files containing a keyword either in the filename or both in the filename and the body.

Tools

GNU/linux locate, find and grep.

locate

locate file with known name:
locate tidyeval_memo.Rmd

find and grep

Find files with the following characteristics:
filetype: Rmd, keyword: ‘tidyeval’, folder: .

search the keyword in the filename only:
find . -type f -name "*tidyeval*.Rmd"

search the keyword in the filename and the file content:
grep -lri "tidyeval" --include="*.Rmd" .

References

This is a first of a series of snippets. The objective is to build progressively a cookbook for Data Science and Machine Learning. As with every cookbook it is important that the desired outcome is clear and the recipe is well classified. Below key references to go further on find tools in linux.

https://www.gnu.org/software/findutils/

https://www.gnu.org/software/grep/

https://www.gnu.org/software/coreutils/

https://www.gnu.org/software/bash/manual/