find walks directory trees; grep searches text. Together they answer “where is this file?” and “which files mention this string?”
find basics
find . -maxdepth 2 -type f -name "*.txt"
find . -type f -mtime -7 # modified in last 7 daysAlways start with a narrow path (. or project root) before searching /.
grep recursion
grep -R "TODO" src/
grep -n "error" log.txt
grep -i "warning" log.txt-n shows line numbers; -i ignores case—common in code review prep.
Exclude noise
grep -R --exclude-dir=.git "function" .Skip .git and node_modules to keep searches fast—pair with Git knowledge.
Important interview questions and answers
- Q: find -name pattern?
A: Shell globs like*.txt—quote them so the shell does not expand early. - Q: grep -R risk?
A: Can search huge trees—scope paths and exclude vendor dirs.
Self-check
- What find flag limits depth?
- What grep flag prints line numbers?
Tip: Add --exclude-dir=.git to grep—learn why in Git.
Interview prep
- find -name?
Filter files by glob pattern.
- grep -R?
Recursive search in directory trees.