How to Clear Memory Cache on 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:
sk@sk:~$ sudo sh -c "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 cacheclear.sh. Say for example, I create cacheclear.sh file in my /home directory:
sk@sk:~$ sudo vi /home/cacheclear.sh
Add the following lines to cacheclear.sh file:
#!/bin/sh sudo sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"
Save and exit the file. Now add this file to your crontab:
sk@sk:~$ sudo 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:
sk@sk:~$ sudo crontab -e -u username
Add the following line at the end:
0 * * * * /home/cacheclear.sh
Save and exit the file. Once you’re done, cron job will run this command every hour and will clear the system memory caches.
After testing with the above command, the sample results are shown in the below screen shots.
Before running the memory cache clearing script.
Like us on Facebook
We need your assistance to stay live
This week Top Posts
- Top Things To Do After Installing Ubuntu 13.10 'Saucy Salamander' : Ubuntu 13.10 Saucy Salamander will be released on coming October 17th with many new salient featur...0 comments |
- News from Kaspersky Lab: Tor is protecting criminals : In a previous article I wrote a bit about Tor. Free browser, relays bouncing your IP all over the ...1 comment |
- Grive: An Unofficial, Open Source Linux Client For Google Drive : A couple of months before, we have featured a Linux client for Google Drive named Syncdrive, which w...2 comments |
- How To Access A LVM Drive / Partition in Ubuntu : Hey Guys, I installed Fedora on an external drive (LVM) recently and was trying to access it from U...0 comments |
- Adding and Deleting Cluster Resources (corosync pacemaker) : In our previous tutorial, we have shown you how to install corosync and pacemaker. We will show y...0 comments |
- Install Satis On Ubuntu Sever 13.10/13.04 : Satis is a simple static composer repository generator. It is used in any composer.json file as i...0 comments |
- Adding and Deleting Cluster Resources (corosync pacemaker)
- News from Kaspersky Lab: Tor is protecting criminals
- Install Satis On Ubuntu Sever 13.10/13.04
- How To Access A LVM Drive / Partition in Ubuntu
- How To Disable Remember Open Files in Sublime Text 3
- Install Sublime Text 3 In Fedora Easily With Fedy
- Grive: An Unofficial, Open Source Linux Client For Google Drive
- Install nSnake Game In Terminal
- How To “Fix E: Could not open file /var/lib/dpkg/status”
- Wow! Linux Foundation To Offer Free Linux Course This Summer Worth $2,400 on EdX
This work by unixmen.com is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
Copyright © 2008-2013 Unixmen.com .