It is possible to clear cache without interrupting any process or service. sync
will flush the file system buffer and
drop_cache
will clean cache without killing any application/service.
# sync; echo 1 > /proc/sys/vm/drop_caches
# sync; echo 2 > /proc/sys/vm/drop_caches
# sync; echo 3 > /proc/sys/vm/drop_caches
- clear swap
# swapoff -a && swapon -a
- clearcache.sh
#!/bin/bash
echo "echo 1 > /proc/sys/vm/drop_caches" && swapoff -a && swapon -a && printf '\n Ram-cache and Swap cleared'
Add executable permission
chmod 755 clearcache.sh
Add cron job
crontab -l > cron_backup
echo "0 10 * * * sudo /home/<user>/clearcache.sh >/dev/null 2>&1" >> cron_backup
crontab cron_backup
rm cron_backup