The I/O Bottleneck
In Ubuntu, the locate command is a blazingly fast way to find files on your system. It achieves this speed by searching a pre-compiled database rather than scanning the live hard drive. To keep this database accurate, Ubuntu uses a background service called mlocate (or plocate on newer versions), which runs a massive, system-wide cron job every single day (usually very early in the morning) to index every file on your drive.
If you are running an Ubuntu server with a massive amount of small files, or if you are running a desktop on an older, slow mechanical hard drive (HDD), this daily indexing process causes massive I/O (Input/Output) spikes. Your disk usage will shoot to 100%, and the entire system will become slow and unresponsive for several minutes while the database builds. If you rarely use the locate command, this background indexing is a severe waste of resources.
How to Disable the Mlocate Cron Job
You can prevent the indexer from running by removing its execution permissions.
- Open your Ubuntu Terminal (or connect via SSH).
- The indexing script is located in the daily cron directory. First, identify if you are using
mlocateorplocateby listing the directory:
ls -l /etc/cron.daily/
- Look for a file named
mlocateorplocate. - To stop the system from executing this script, you must remove the executable (
+x) bit from the file. Run the following command (adjust the filename if necessary):
sudo chmod -x /etc/cron.daily/mlocate
- Verify the change by listing the file again. It should no longer be colored green (indicating it is executable) in standard terminal themes:
ls -l /etc/cron.daily/mlocate
The cron daemon will now ignore the file during its daily maintenance routine. Your disk will no longer spike to 100% usage every morning. Note that the locate command will now return outdated results, so you should rely on the live find command instead.