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
Syntax:
sudo swapoff -a sudo swapon -a
You can run the # free -h command to see the difference between used and free memory before and after clearing the swap space
Add the above command to a cron script, here we are going to combine these two different commands into one single command, to form a proper script which will help us to clear Swap Space and RAM Cache.
echo 3 > /proc/sys/vm/drop_caches & & swapoff -a & & swapon -a & & printf ‘\n%s\n’ ‘ ‘ Ram-cache and the swap get cleared’
Now Ram cache and swap will be cleared you can run # free -h command to see
After running the command, you will get output like this
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.
Contact Us