Linux Error Guide: 'No such file or directory' when Searching — Fix find and locate
Fix Linux file-search failures with find and locate: handle a stale updatedb database, wrong search path, case sensitivity, permission-hidden directories, and unquoted patterns.
- #linux
- #troubleshooting
- #errors
- #find
Stuck on this Linux Admins error? Get the free incident triage checklist
A one-page PDF — the exact steps to isolate, fix, and verify a production error like this one. No spam, unsubscribe anytime.
Overview
You know a file exists, but the tools that should find it come up empty or error out. With find, a bad starting path or an unquoted pattern is the usual culprit:
$ find /opt/aps -name app.conf
find: '/opt/aps': No such file or directory
With locate, the database is often just stale or missing:
$ locate app.conf
locate: can not open '/var/lib/mlocate/mlocate.db': No such file or directory
find searches the live filesystem in real time, so its failures are about the path you gave it and permissions. locate reads a prebuilt index (updatedb), so it can be fast but wrong — it will miss files created since the last index run and list files already deleted. Knowing which tool you’re using explains most “can’t find it” surprises.
Symptoms
find <path> ...printsNo such file or directoryfor the starting directory itself.findreturns nothing for a file you canls, or reportsPermission deniedon subtrees.locate <name>returns nothing for a file you just created.locatelists a path that no longer exists on disk.- A pattern with
*behaves unexpectedly because the shell expanded it beforefindsaw it.
Common Root Causes
- Wrong or nonexistent start path —
finderrors immediately if the directory you told it to search doesn’t exist (typo, wrong mount). - Stale
locatedatabase —updatedbhasn’t run since the file was created; the index is behind reality. - Missing/uninitialized
mlocatedb — on minimal or fresh systems the database file doesn’t exist yet. - Case sensitivity —
-name App.confwon’t matchapp.conf; Linux filesystems are case-sensitive. - Unquoted glob — the shell expands
*.logbeforefind, sofindsearches for the wrong literal name. - Permission-hidden directories —
findcan’t descend into directories without execute permission, silently missing files.
Diagnostic Workflow
Confirm the start path exists before blaming find:
ls -ld /opt/aps # does the starting directory exist?
find / -type d -name aps 2>/dev/null # locate the real directory name/path
Always quote the pattern so the shell doesn’t expand it, and use case-insensitive matching when unsure:
find /opt -name '*.conf' # quoted: find handles the glob
find /opt -iname 'app.conf' # -iname = case-insensitive
Separate real “not found” from permission-hidden results by discarding errors deliberately:
find / -name app.conf 2>/dev/null # hide Permission denied noise
sudo find / -name app.conf # search as root to see restricted dirs
For locate, refresh the index and verify it exists:
sudo updatedb # rebuild the mlocate/plocate database
locate -e app.conf # -e = only print files that still exist
locate --statistics # DB path, entry count, last build
Example Root Cause Analysis
A sysadmin swore a log file existed but find reported nothing:
$ find /var/log -name *.log
find: paths must precede expression: 'auth.log'
The shell had expanded *.log in the current directory before find ran, turning the command into find /var/log -name access.log auth.log .... Quoting the pattern fixed the parse, but it still returned nothing for a file owned by root under a 700 directory. Running as root revealed it:
$ find /var/log -iname '*.log' 2>/dev/null # still missing one
$ sudo find /var/log -iname '*.log' | grep audit
/var/log/audit/audit.log # inside 700 audit dir
Two root causes stacked: an unquoted glob (shell expansion) and a 700 directory that the unprivileged user couldn’t traverse, so find skipped it. Quoting the pattern and searching with sufficient privileges surfaced the file. A parallel locate miss for a freshly created file was resolved simply by running sudo updatedb.
Prevention Best Practices
- Always quote
findpatterns ('*.log') so the shell doesn’t pre-expand them. - Use
-inamewhen case is uncertain, since Linux filenames are case-sensitive. - Remember
locatereflects the lastupdatedb; runupdatedbafter bulk file changes or usefindfor anything just created. - Add
2>/dev/nullto suppress permission noise, but search withsudowhen results may live in restricted directories. - Verify the start path exists (
ls -ld) before deepfindruns in scripts, and fail clearly if it doesn’t. - Keep the
mlocate/plocatecron or systemd timer enabled so the index stays reasonably fresh.
Quick Command Reference
ls -ld <startdir> # confirm find's start path exists
find <path> -iname '<pattern>' # case-insensitive, quoted pattern
find / -name '<name>' 2>/dev/null # suppress Permission denied noise
sudo find / -name '<name>' # search restricted directories
sudo updatedb # rebuild locate database
locate -e <name> # only show files that still exist
locate --statistics # inspect the locate index
Conclusion
When a search “can’t find” a file that exists, first identify the tool. find works live, so check the start path, quote your glob, use -iname, and search with enough privilege to enter restricted directories. locate works from an index, so a fresh file or a stale entry just means updatedb needs to run — use locate -e to filter deleted paths. Matching the tool’s behavior to your expectation clears up nearly every “the file is right there” mystery.
Fixed it? Get 500 Linux Admins & DevOps AI prompts — free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.
Did this fix your issue?
Get 500 Battle-Tested DevOps AI Prompts — Free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.