How to Clear RAM Memory Cache, Buffer and Swap Space on Linux

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

65 Responses

  1. Angelo says:

    How can I stop or remove the echo 1 because its running

  2. mandar says:

    Hi,

    When i try to create .sh file with given contents, its showing error as bash: ./clearcacahe.sh: /bin/bash^M: bad interpreter: No such file or directory

    • prashant kumar says:

      Use file format use command dos2unix as above file is in DOS format.

    • Ravi Saive says:

      @Mandar,

      Seems like you have a dos line ending file. The clue is the ^M.

      You need to save the file using Unix line endings, for example – open your script with vi/vim editor and then hit (key ESC) and type this:

      :set fileformat=unix
      

      If you have a dos2unix command line program that will also do this for you.

  3. Md Sameer says:

    Thanks to provide such a great article.

    I am having one doubt about echo 3 if I use "echo 3" in my production environment to clean buffer cache. Any impact of above command in os RAM ? Will it delete useful data of physical RAM ?

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.