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

Linux System has three command clear cache without interrupting any services.

1)Clear PageCache only.

# sync; echo 1 > /proc/sys/vm/drop_caches

2)Clear inodes and dentries.

# sync; echo 2 > /proc/sys/vm/drop_caches

3)Clear  dentries, pagecache and inodes.

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

Free Buffer and Cache in Linux script

clear_cache.sh script in add

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

Set execute permission on the clear_cache.sh file.

# chmod 755 clear_cache.sh

Set crontab - 

# crontab -e

Append the below line, save and exit to run it at 1 am daily. Add this code in the crontab.

0  1  *  *  *  /path/to/clear_cache.sh

Clear Swap Space in Linux

# swapoff -a && swapon -a

Check Memory status command 

#free -m

To clean the apt-cache on Ubuntu running this command

#sudo apt-get clean

Remove Old Kernels

#sudo apt-get autoremove --purge

Directory  var/cache folder remove

Also Remove the .Cache Folders and Free Up Space On Your Linux PC.

#sudo rm -rf ~/.cache/thumbnails/*

Cache clear

You can also download BleachBit software use in linux.


Post a Comment