Last active
August 26, 2020 21:49
-
-
Save WIttyJudge/efec138164d5361150e25c471fad1abd to your computer and use it in GitHub Desktop.
The script will clean RAM in linux operation system.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can download script and run using
or run script remotely: