Skip to content

Instantly share code, notes, and snippets.

@trinib
Last active February 9, 2022 16:37
Show Gist options
  • Save trinib/0ae1e7cd56178358ee28bb0828daab4f to your computer and use it in GitHub Desktop.
Save trinib/0ae1e7cd56178358ee28bb0828daab4f to your computer and use it in GitHub Desktop.
"Clean/Clear Ram & Swap" Script For Linux
  1. Open and make a sh file:

    sudo nano clean.sh
    
  2. Copy and paste text below:

    echo
    
    printf "                              🧹🧹🧹 Memory Before Clean 🧹🧹🧹"
    
    echo
    
    echo
    
    free -m
    
    sync; sudo echo 2 | sudo tee /proc/sys/vm/drop_caches
    
    echo
    
    printf "                              🧹🧹🧹 Memory After Clean 🧹🧹🧹"
    
    echo
    
    echo
    
    free -m
    
    echo
    
    echo
    
    printf "DONE !!!"
    
    echo
    
    printf "🧽🧽🧽 RAM CACHE CLEARED 🧽🧽🧽" 
    
    echo
    

To save : Ctrl+x then y then Enter

  1. Set permission to file:

    sudo chmod 755 clean.sh
    
  2. Run Script:

    sudo ./clean.sh
    

TIP

Add a keyboard shorcut to execute script.

OR

Create cron job to schedule a time to run the script.

  1. Open cron file:

    crontab -e
    
  2. Enter text at end file:

    0 */2 * * * sudo ./clean.sh
    

Script will run every 2 hours

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