Clearing Buffer/Cache in Linux

Buffer memory is used for storing data temporarily which is being transferred between the CPU and the hard drives. similarly as RAM memory Cache, buffer can aslo accumulate over time and make our system slow. to clear buffer memory we can use the command below:

sudo sync && echo 1 > /proc/sys/vm/drop_caches

 

Here you can see that the buff/cache is being cleared.

Now using Linux Kernel, to free Buffer and Cache in Linux we will Create a shell script to auto clear RAM cache daily, through a cron scheduler task., the command vim script.sh is used to create a shell script “script.sh”

Now in script, you have to add the below syntax:

echo " echo 3 >  /proc/sys/vm/drop_caches"

Now to set run permission, to clear ram cache, you have to call the script whenever required, setting a cron to clear RAM caches every day for 3 hours.

# chmod 755 script.sh

To schedule the script so that it run daily, open the crontab editor by running the following command.

# crontab -e

Then add this line at the end of the file.

0 0 * * * /path/to/script.sh

This line will run the script at midnight every day. User has to replace “/path/to/script.sh” with the actual path of the script file. 

Then save and exit the editor. Now our script will finally run automatically executed daily at midnight to free up the RAM cache.

How to Clear RAM Memory Cache, Buffer and Swap Space on Linux

RAM memory is a very important component of the computer system. it helps store data and code currently used by the operating system. This article will show how to Clear RAM Memory Cache, Buffer, and Swap Space on Linux. In every system, we come across caches that have unwanted files and can harm our system, the same thing happens in the Linux cache; if you want to clear the cache and free some memory, then Linux has many commands to do that.

Similar Reads

To Clear RAM memory Cache in Linux:

RAM memory Cache is a type of memory that stores accessed data to speed up the performance of the system and provide a better and faster experience to the user. In all the Linux systems we have three options to clear the cache without interrupting any services or processes....

Clearing Buffer/Cache in Linux:

Buffer memory is used for storing data temporarily which is being transferred between the CPU and the hard drives. similarly as RAM memory Cache, buffer can aslo accumulate over time and make our system slow. to clear buffer memory we can use the command below:...

To Clear Swap Space in Linux:

Swap space is used a part of hard drive that is used as a supplement of RAM memory. You can clear the swap space by running the below command...

Frequently Asked Questions

How to clear buffer cache swap in Linux?...

Contact Us