When new files appear on your Linux system (especially after installs/downloads), traditional search utilities won't detect them immediately because they either:
- Rely on pre-built indexes (locate)
- Need explicit directory specification (find)
1. For 'locate' Command
The locate
command depends on updatedb
which typically runs daily via cron. Force a manual update with:
sudo updatedb
# Verify with:
locate filename.ext
2. For 'find' Command
find
doesn't use indexes but requires explicit paths. Best practices:
# Basic scan:
find /path/to/search -name "filename.ext"
# Time-limited search (files modified in last 30 mins):
find / -type f -mmin -30
# Case-insensitive:
find /home -iname "*.deb"
3. Alternative: mlocate
Modern systems often use mlocate
instead of traditional locate. Update its database with:
sudo /etc/cron.daily/mlocate # On Debian/Ubuntu
# Or directly:
sudo /usr/bin/updatedb.mlocate
Partial Directory Rescan
For large systems, limit indexing scope:
sudo updatedb --localpaths='/home /usr/local' --netpaths=''
Real-time Monitoring
For development environments, consider inotify-tools:
sudo apt-get install inotify-tools
inotifywait -m -r /path/to/watch
- Check
/etc/updatedb.conf
for excluded paths - Verify cron jobs:
sudo cat /etc/cron.daily/mlocate
- For network filesystems: add
--netpaths
to updatedb
When working with Linux file search tools like find
and locate
, a common frustration occurs when newly added files don't appear in search results. This happens because:
locate
relies on a pre-built database (updated viaupdatedb
)find
performs real-time searches but can be slow for large directories
For locate/updatedb
To manually rebuild the locate database:
# As root or with sudo:
sudo updatedb
# Verify with:
locate filename.ext
For more control over updatedb:
# Update specific directories only
sudo updatedb --localpaths='/path/to/dir /another/path'
For find
No index needed, but here's an optimized find command:
find /search/path -name "*.ext" -type f -mtime -1
# -mtime -1 finds files modified in last 24 hours
mlocate (modern locate)
# Install first:
sudo apt-get install mlocate
# Then use same updatedb command
fd-find (user-friendly alternative)
# Installation:
sudo apt install fd-find
# Basic usage (auto-ignores hidden/vcs files):
fdfind pattern
Edit the cron job for regular updates (usually in /etc/cron.daily/mlocate
or similar):
# Example daily update at 3AM
0 3 * * * root /usr/bin/updatedb -f "tmpfs,proc"
For large filesystems:
- Exclude virtual filesystems with
-e "tmpfs,proc"
- Limit depth:
find / -maxdepth 3 -name pattern
- Use
-xdev
to stay on single filesystem
If files still don't appear:
# Check updatedb config:
cat /etc/updatedb.conf
# Look for PRUNEPATHS and PRUNEFS exclusions