grep: No such file or directory
Diagnose and fix 'No such file or directory' when grep fails due to shell globbing, quoting, or incorrect file paths.
grep produces "No such file or directory" when the specified file does not exist, or when shell globbing expands to zero matches before grep receives the filename argument.
What Causes This Error
The filename or path is misspelled. Shell globbing (
*.log) expanded to zero matches — when no files match the glob pattern, Bash passes the literal string
*.log to grep, which fails because no file is literally named
*.log.
How to Fix
- Verify the file exists:
ls -la /var/log/nginx/access.log- Use quotes around glob patterns to prevent premature expansion, or verify matches exist:
ls /var/log/*.log
grep "error" /var/log/*.log- For recursive searches, use
grep -rinstead of shell globs:
grep -r "error" /var/log/