Skip to content

Instantly share code, notes, and snippets.

@WIttyJudge
Last active August 26, 2020 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WIttyJudge/efec138164d5361150e25c471fad1abd to your computer and use it in GitHub Desktop.
Save WIttyJudge/efec138164d5361150e25c471fad1abd to your computer and use it in GitHub Desktop.
The script will clean RAM in linux operation system.
#!/usr/bin/env bash
# Running the script only by root
[ "$EUID" != 0 ] && echo "You have to run this script with superuser" && exit 1
MEMINFO="cat /proc/meminfo"
# # Get memory information
MEM_FREE="$( $MEMINFO | grep MemFree | tr -cd [:digit:] )"
MEM_FREE_MIB="$(expr $MEM_FREE / 1024)"
# # Output information
echo -e "This script will clean you ram.\nNow you have $MEM_FREE_MIB MiB available memory."
# # Clean ram
sync; echo 3 > /proc/sys/vm/drop_caches
# # Get memory info after cleaning
AFTER_MEM_FREE="$( $MEMINFO | grep MemFree | tr -cd [:digit:] )"
AFTER_MEM_FREE_MIB="$(expr $AFTER_MEM_FREE / 1024)"
# # Output information
echo "This cleaned $(expr $AFTER_MEM_FREE_MIB - $MEM_FREE_MIB) MiB. Now you have $AFTER_MEM_FREE_MIB MiB."
@WIttyJudge
Copy link
Author

WIttyJudge commented Jul 8, 2020

You can download script and run using

bash ./cleanRAM.sh

or run script remotely:

sudo sh -c "$(curl -fsSL https://gist.githubusercontent.com/WIttyJudge/efec138164d5361150e25c471fad1abd/raw/321b4d6e0561304647252848a5089236f751a7f2/cleanRAM.sh)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment