#!/bin/bash | |
## Bash Script to clear cached memory on (Ubuntu/Debian) Linux | |
## By Philipp Klaus | |
## see <http://blog.philippklaus.de/2011/02/clear-cached-memory-on-ubuntu/> | |
if [ "$(whoami)" != "root" ] | |
then | |
echo "You have to run this script as Superuser!" | |
exit 1 | |
fi | |
# Get Memory Information | |
freemem_before=$(cat /proc/meminfo | grep MemFree | tr -s ' ' | cut -d ' ' -f2) && freemem_before=$(echo "$freemem_before/1024.0" | bc) | |
cachedmem_before=$(cat /proc/meminfo | grep "^Cached" | tr -s ' ' | cut -d ' ' -f2) && cachedmem_before=$(echo "$cachedmem_before/1024.0" | bc) | |
# Output Information | |
echo -e "This script will clear cached memory and free up your ram.\n\nAt the moment you have $cachedmem_before MiB cached and $freemem_before MiB free memory." | |
# Test sync | |
if [ "$?" != "0" ] | |
then | |
echo "Something went wrong, It's impossible to sync the filesystem." | |
exit 1 | |
fi | |
# Clear Filesystem Buffer using "sync" and Clear Caches | |
sync && echo 3 > /proc/sys/vm/drop_caches | |
freemem_after=$(cat /proc/meminfo | grep MemFree | tr -s ' ' | cut -d ' ' -f2) && freemem_after=$(echo "$freemem_after/1024.0" | bc) | |
# Output Summary | |
echo -e "This freed $(echo "$freemem_after - $freemem_before" | bc) MiB, so now you have $freemem_after MiB of free RAM." | |
exit 0 |
This comment has been minimized.
This comment has been minimized.
wow, |
This comment has been minimized.
This comment has been minimized.
We need to have bc installed to run the script |
This comment has been minimized.
This comment has been minimized.
Thanks a lot...!! |
This comment has been minimized.
This comment has been minimized.
hello!
Many thanks for any help |
This comment has been minimized.
This comment has been minimized.
You need to install "bc" to run this script. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Permission denied |
This comment has been minimized.
This comment has been minimized.
Works like a charm, thanks. Just make sure to install bc !! sudo apt-get install bc then run script as follows: sudo ./flushram.sh My result: At the moment you have 223 MiB cached and 2425 MiB free memory. |
This comment has been minimized.
This comment has been minimized.
dont work on ubuntu |
This comment has been minimized.
Newbie to UNIX.
Thanks a Lot !!!