find files containing a text
Search every file under a folder for a word or a phrase, and show where it is.
Steps
-
grep -rn 'some text' .every line containing the text, under this folder, with file and line number
-
grep -rl 'some text' .only the names of the files that contain it
-
grep -rni 'some text' .the same, ignoring upper and lower case
-
grep -rnw 'word' .only where it is a whole word
-
grep -rn --include='*.py' 'some text' .only in the files of one kind
-
grep -rn --exclude-dir={.git,node_modules} 'some text' .skipping folders you do not want searched
-
rg 'some text'the same, faster, with ripgrep, which skips what .gitignore lists
Notes
-Iskips binary files, and2>/dev/nullhides the files you may not read.
Commands used
greprgfind
Each has a page in lore: lore grep opens it.
Related recipes
- compare two foldersFind which files differ between two folders, or are only in one of them.
- count lines, words and filesCount the lines of a file or of a command's output, the words, and the files in a folder.
- delete lines containing a textRemove every line of a file that contains a word, or keep only those lines.
- exclude a folder from findSearch with find without going into folders like .git or node_modules.