Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RodrigoDornelles/4e4721187f80a767a2a9126545950ce8 to your computer and use it in GitHub Desktop.
Save RodrigoDornelles/4e4721187f80a767a2a9126545950ce8 to your computer and use it in GitHub Desktop.
clear memory cache linux
#!/usr/bin/env bash
if [ `whoami` != 'root' ]
then
echo "[!] Error: requires root!";
exit;
fi
echo " * Clearing ram PageCache";
sync;
echo 1 > /proc/sys/vm/drop_caches;
echo " * Clearing ram dentries and inodes";
sync;
echo 2 > /proc/sys/vm/drop_caches;
echo " * Clearing disk swap";
sync;
swapoff -a && swapon -a;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment