Find files on system containing specific text

To search for text inside of files and show a snippet containing the match, use the following command:

grep -rnw {PATH} -e {TEXT_TO_SEARCH_FOR}

Such as:

grep -rnw / -e examplephrase

If your search parameter includes spaces or special characters, make sure to enclose it in quotes:

grep -rnw / -e "my example phrase"

To ignore “certain permission denied” errors, exclude them from being output:

grep -rnw / -e SEARCHPHRASEHERE 2>&1 | grep -v "Permission denied" | grep -v "Operation not permitted" | grep -v "Invalid argument" | grep -v "Input/output error" | grep -v "No such file or directory" | grep -v "Operation not supported"

To exclude all errors from being output:

2>/dev/null grep -rnw / -e SEARCHPHRASEHERE

To match partial words:

grep -rn / -e SEARCHPHRASEHERE

If you’d rather just get a list of filenames that include the text, use this command instead:

For further info, see the grep manual.