Search directory for a word / text via the command line
By Elliot J. Reed
By using grep we can quickly search through files for a specific string of text
To list all occurrences of a particular string / text in your Bash (or ZSH or Shell) command line, run:
grep -ni "Text to search for" .You can also search recursively in subdirectories by adding the r flag, for example:
grep -rni "Text to search for" .If you use this sort of thing a lot, you could always add this to your ~/.profile, ~/.bashrc, or ~/.zshrc in handy aliases like:
# Search current directory for files containing specified string (Usage: searchdir "Search Term")searchdir() { if [[ $# -eq 0 ]] ; then echo -e "\e[0;31mPlease provide a string / search term\e[0m" else grep -rni "$@" . fi}For more shortcuts like this, see my useful ZSH and Bash aliases and useful ZSH and Bash functions.