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?
~/bin
directory and add it to your path or place it in the/usr/local/bin
folder which is already on your path – George Udosen Nov 12 '18 at 22:11select
bash command to present your menu. – glenn jackman Nov 12 '18 at 22:12