When the locate
command stops working, running updatedb
should refresh the file database. But what happens when the system can't find updatedb
itself? This typically indicates either:
- The mlocate package isn't installed
- The command isn't in your $PATH
- Filesystem permissions prevent execution
First check if mlocate is installed:
rpm -q mlocate # For RHEL/CentOS/Fedora
dpkg -l mlocate # For Debian/Ubuntu
pacman -Qs mlocate # For Arch
If nothing returns, install it with:
sudo yum install mlocate # RHEL/CentOS
sudo apt install mlocate # Debian/Ubuntu
sudo pacman -S mlocate # Arch
If installed but still not found, try these approaches:
# Full path execution
/usr/bin/updatedb
# Using find to locate the binary
sudo find / -name updatedb 2>/dev/null
# Verify PATH contains standard binary directories
echo $PATH | grep -E "/usr/local/bin|/usr/bin|/bin"
For immediate needs, create a temporary solution:
# Create custom locate database
sudo find / -type f > ~/my_locate_db 2>/dev/null
# Search using grep
grep "search_term" ~/my_locate_db
Investigate potential permission issues:
# Check file permissions
ls -l $(which updatedb)
# Verify sudo works
sudo -l updatedb
# Check environment variables
sudo env | grep PATH
Different distributions handle locate differently:
- RHEL 8+: Uses
plocate
instead of mlocate - macOS: Uses
mdfind
instead of locate - Minimal Installations: May require additional dependencies
For recurring issues, set up a cron job:
# Add to crontab (runs daily at 2AM)
(crontab -l 2>/dev/null; echo "0 2 * * * /usr/bin/updatedb") | crontab -
When locate isn't available, consider:
# Using find with optimized parameters
find / -name "pattern" -type f 2>/dev/null
# fd (faster alternative)
fd "pattern" /search/path
When the locate
command fails to work, the immediate fix would be updating its database with updatedb
. However, many users encounter the frustrating "bash: updatedb: command not found
" error, which indicates deeper system configuration issues.
First verify if mlocate (or findutils) package is installed:
# For Debian/Ubuntu systems
sudo apt list --installed | grep mlocate
# For RHEL/CentOS systems
rpm -qa | grep mlocate
If not installed, install it with:
# Debian/Ubuntu
sudo apt install mlocate -y
# RHEL/CentOS
sudo yum install mlocate -y
# Fedora
sudo dnf install mlocate -y
The command might exist but not in your PATH. Try finding the binary:
sudo find / -name updatedb 2>/dev/null
If found but not in PATH, either add its directory to PATH or create an alias:
echo 'alias updatedb="/usr/bin/updatedb"' >> ~/.bashrc
source ~/.bashrc
Even when installed, permission issues might prevent execution:
ls -l $(which updatedb)
sudo chmod +x $(which updatedb)
Most systems run updatedb automatically via cron. Check if it's configured:
sudo cat /etc/cron.daily/mlocate
If missing, create a daily cron job:
sudo tee /etc/cron.daily/mlocate <<'EOF'
#!/bin/sh
/usr/bin/updatedb -f "nfs,smbfs,ncpfs,proc,devpts" -e "/tmp,/var/tmp,/usr/tmp,/afs,/net"
EOF
sudo chmod +x /etc/cron.daily/mlocate
If all else fails, consider alternatives:
# Using find with recent files
find / -mtime -7
# Using fd (modern alternative)
sudo apt install fd-find
fdfind --type f
Enable verbose output when manually running updatedb:
sudo /usr/bin/updatedb --verbose
Check system logs for errors:
journalctl -xe | grep -i updatedb