How to clear cache in Linux

Here I would like to share a script which you can use to clear your cache memory.

IMPORTANT NOTICE:
This is something one should not do as cache is used to speed up your work activity building a cache memory but still if you feel to clear your cache memory size then you can follow the following steps:


Create a script

# vi clearcache.sh
#!/bin/bash
sync; echo 3 > /proc/sys/vm/drop_caches

save and exit

# chmod +x clearcache.sh
Sync should be run beacause this is a non destructive operation and dirty objects are not freeable. So we run sync in order to make sure all cached objects are freed.
echo 1 is clearing only page cache
echo 2 is to clear free dentries and inodes
echo 3 is clearing page cache, dentries and inodes


Follow the below link for more tutorials

Leave a Comment

close button