How to Clear Memory Cache on Linux

Simple and easy way to clear memory cache in  LINUX

By default, every Linux OS has an efficient memory management system used to clear the buffer cache periodically. You can manually free up the memory cache with the following simple command:

[] # sync; echo 3 > /proc/sys/vm/drop_caches

However, if you want to force the Linux OS to do clearing memory cache on a particular interval, just add the command to cron job. Here, I show you how.

Open up your terminal and enter the following command to create a file called Say for example, I create file in my /home directory:

[] #  vi /home/

Add the following lines to file:

sudo sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"

Save and exit the file. Now add this file to your crontab:

[] #  crontab -e

This command opens the current user cron file. If you want to set it to some other user, use the following command instead:

[] #  crontab -e -u username

Add the following line at the end:

0 * * * * /home/

Save and exit the file. Once you’re done, cron job will run this command every hour and will clear the system memory caches.

NOTE:- Before running the memory cache clearing script check if your running application is dependent on cache or not.