When you care about the file name (or its path) rather than the file’s contents, grep is the wrong tool—grep searches inside files.
Use a command that filters file paths instead:
────────────────────────────────────────────────────────────
- Classic POSIX way – find
────────────────────────────────────────────────────────────
From the repo root
find . -type f -name 'name_of_script*'
• -type f → only regular files
• -name pattern → glob on the basename (you can add * before/after, e.g. '*name_of_script*')
• Add -print or nothing (default is print).
If you also want to follow symlinks: add -L.
If you want case-insensitive: replace -name with -iname.
────────────────────────────────────────────────────────────
2) Git-aware (faster in big repos) – git ls-files
────────────────────────────────────────────────────────────
git ls-files | grep -i 'name_of_script'
git ls-files only shows files tracked by git, so you avoid build/, node_modules/, etc.
────────────────────────────────────────────────────────────
3) A modern, fast finder – fd / ripgrep / rg
────────────────────────────────────────────────────────────
fd name_of_script # fuzzy by default, respects .gitignore
Using ripgrep just for file names
rg -g 'name_of_script' --files
────────────────────────────────────────────────────────────
Tips & variations
────────────────────────────────────────────────────────────
• Need an exact basename match?
find . -type f -name 'name_of_script' # no wildcard
• Need to limit to certain extensions?
find . -type f -name 'name_of_script*.sh' # only .sh
• Exclude directories (e.g., tests/, docs/):
find . -type f -name 'name_of_script' -not -path './tests/' -not -path './docs/'
• Show file size + mod-time (useful when there are multiple copies):
find . -type f -name 'name_of_script' -printf '%TY-%Tm-%Td %TH:%TM %s bytes %p\n'
────────────────────────────────────────────────────────────
Why grep -R gave too many hits
────────────────────────────────────────────────────────────
grep -R walks every file and searches inside it, so lines like:
#!/usr/bin/env bash
name_of_script arg1 arg2
match too. Switching to one of the “find file names” techniques above avoids that confusion altogether.
Give one of those a try—find is everywhere, fd/rg are great if you have them installed.