[grep] Search a directory and its subdirectories

Created on November 30, 2026

Use grep -r to search through a directory tree. This example creates a log file inside logs/archive and searches under logs.

mkdir -p logs/archive
printf 'INFO started\nERROR timeout\n' > logs/archive/app.log
grep -r 'ERROR' logs/
logs/archive/app.log:ERROR timeout

-r is short for --recursive.

Shell command grep