Clear dentries and inodes:
> sync; echo 2 > /proc/sys/vm/drop_caches
Clear pagecache, dentries and inodes
> sync; echo 3 > /proc/sys/vm/drop_caches
:: sync will flush the file system buffer. Command Separated by “;” run sequentially.
Create a new shell script calles “clearcache.sh” for cronjob
# Note, we are using “echo 3”, but it is not recommended in production instead use “echo 1”
echo “echo 3 > /proc/sys/vm/drop_caches”
> chmod 755 clearcache.sh
> crontab -e
> 0 2 * * * /path/to/clearcache.sh
:: when you have scheduled the script to clear ram cache everyday at 2am. Everyday at 2am the script is executed and it flushes your RAM cache.
Clear swap space:
> swapoff -a && swapon -a
> echo 3 > /proc/sys/vm/drop_caches && swapoff -a && swapon -a && printf ‘\n%s\n’ ‘Ram-cache and Swap Cleared’
> free -h
> cat /proc/meminfo : The next way to check memory usage is to read the /proc/meminfo file. Know that the /proc file system does not contain real files.
> vmstat -s : lays out the memory usage statistics much like the proc command.