Existence Checks (-e)
Because locate queries a database that can be up to 24 hours old, results can include:
- Ghost files: files that have been deleted since the last
updatedb - Missing new files: files created after the last
updatedb
The -e flag (--existing) tells locate to verify each result against the live filesystem before printing it. Only files that actually exist right now are shown.
Basic Usage
# Without -e: may include deleted files
locate nginx.conf
# With -e: guaranteed to exist right now
locate -e nginx.conf
Performance Note
-e makes locate slower because it performs a stat() system call for every candidate result. For large result sets (thousands of paths), this adds noticeable latency. Use -e only when accuracy matters.
Scripting with -e
Use -e in scripts that will act on the results, to avoid operating on deleted paths:
#!/bin/bash
# Find all php.ini files and check their memory settings
locate -e "php.ini" | while read -r conf; do
echo "=== $conf ==="
grep "memory_limit" "$conf"
done
Checking File Count
# How many nginx.conf files exist right now?
locate -e -c nginx.conf
Combining -e with Other Filters
# Existing .log files from a quick locate, piped to find for size info
locate -e "*.log" | xargs ls -lh 2>/dev/null | sort -k5 -hr | head -20