1

I have a shell script i use frequently to manually clear the dentries, inodes and page cache in my RAM: ramflush.sh

#!/bin/bash
echo " ██▀███   ▄▄▄       ███▄ ▄███▓   "
echo "▓██ ▒ ██▒▒████▄    ▓██▒▀█▀ ██▒  _____ "
echo "▓██ ░▄█ ▒▒██  ▀█▄  ▓██    ▓██░   |   | F"
echo "▒██▀▀█▄  ░██▄▄▄▄██ ▒██    ▒██    |   |  L "
echo "░██▓ ▒██▒ ▓█   ▓██▒▒██▒   ░██▒   |   |   U"
echo "░ ▒▓ ░▒▓░ ▒▒   ▓▒█░░ ▒░   ░  ░   \___|    S       _"
echo "  ░▒ ░ ▒░  ▒   ▒▒ ░░  ░      ░     ||  ____H__  -( (-"
echo "  ░░   ░   ░   ▒   ░      ░        |_'(-------)  '-'"
echo "   ░           ░  ░       ░           |       /"
echo "___________VERSION 1.0______________,-\__..__|_____"
echo " "
read -p "[*] Do you have a need to flush?:    " yn
case $yn in
   [Yy]* ) ;;
   [Nn]* ) echo "[X] Understood."; exit;;
       * ) echo "[X] No input detected. Exiting."; exit;;
 esac

echo " "
echo " <=== OPTIONS ===>"
echo " "
echo "1. Clear RAM Page Cache."
echo "2. Clear Dentries and Inodes."
echo "3. Clear Page Cache, Dentries and Inodes."
echo " "
read -p "[*] Choose what to flush:    " ans

case $ans in
   [1]* ) echo 1 > /proc/sys/vm/drop_caches; echo "[*] Cache Cleared.";;
   [2]* ) echo 2 > /proc/sys/vm/drop_caches; printf "[*]Dentries Cleared.\n[*]Inodes Cleared.\n";;
   [3]* ) echo 3 > /proc/sys/vm/drop_caches; printf "[*]Page Cache Cleared\n[*]Dentries Cleared.\n[*]Inodes Cleared.\n";;
      * ) echo "[X] No input detected. Exiting."; exit;;

esac

However it gets tiresome constantly changing back to my home directory, then going in to a folder and calling the script. I also refuse to just do the commands manually because it defies the point to me having made the script.

Is there a way I can add this to my bash shell in order to be able to run the script from any directory simply by typing ramflush in order to call and run this script, similar to nmap or ping?

Would I have to add it to the package manager and how do I go about doing this?

2 Answers2

3

The quickest way to do this, would be using an alias.

Add this to your .bashrc:

alias ramflush='/path/to/your/script/ramflush.sh'

Then open a new terminal or run source ~/.bashrc to reload your bash configuration.

You can now call ramflush anywhere in the terminal.

Wayne_Yux
  • 4,942
2

You can drop that script as ramflush without the sh extenion in two places:

  1. ~/bin or
  2. /usr/local/bin,

for the first case add that path in .bashrc with the line export PATH=$PATH:$HOME/bin and the other is already in your path. Now you can simply type ramflush.

George Udosen
  • 37,534