Clear memory cache every 5 seconds

Create a shell script clear.sh using bash.

$ vim clear.sh

#!/bin/bash
while true
do
 sync; echo 3 > /proc/sys/vm/drop_caches
 sleep 5
done

Set execute permissions

$ chmod u+x clear.sh

Now, execute this shell script in the background using “nohup” as shown below. This will keep executing the script even after you logout from your session. This will execute your clear.sh shell script every 5 seconds.

$ nohup ./clear.sh &

Leave a Reply

Your email address will not be published. Required fields are marked *