How to Clear Memory Cache on Linux

By default, every Linux OS has an able anamnesis administration arrangement acclimated to bright the absorber accumulation periodically. You can manually chargeless up the anamnesis accumulation with the afterward simple command:

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

However, if you appetite to force the Linux OS to do allowance anamnesis accumulation on a accurate interval, aloof add the command to cron job. Here, I appearance you how.

Open up your terminal and access the afterward command to actualize a file alleged cacheclear.sh. Say for example, I actualize cacheclear.sh file in my /home directory:

 

sudo nano /home/cacheclear.sh

if nano editor not install run this command to install.

for Centos

yum install nano -y

for Ubuntu

apt-get install nano -Y

After add the following lines to cacheclear.sh file:

#!/bin/sh
sudo sh -c “sync; echo 3 > /proc/sys/vm/drop_caches”

Now save it and exit the file. Press by Ctrl+X then Y and enter.

Now add this file to your Crontab:

sudo crontab -e

This command opens the accepted user cron file. If you appetite to set it to some added user, use the afterward command instead:

sudo crontab -e -u username

Now add the following line at the end:

0 * * * * /home/cacheclear.sh

Save and avenue the file. Once you’re done, cron job will run this command every hour and will bright the arrangement anamnesis caches.

The anamnesis caches are bargain a bit.

Related posts

Leave a Reply

%d bloggers like this: