How to clear cached memory on ubuntu

By default the Linux OS has a very efficient memory management process that should be freeing any cached memory on the machine that it is being run on. However when it comes to Cached memory the Linux OS may at times decide that the Cached memory is being used and is needed which can lead to memory related issues and ultimately take your server of any potentially free memory. To overcome this you can force the Linux OS to free up and stored Cached memory.

If you want to clear cached memory on ubuntu run the following command from your terminal

sync; sudo echo 3 > /proc/sys/vm/drop_caches

If you want to run this command every one hour you can use crontab to run this

Thanks to john for this tip

Sponsored Link

You may also like...

20 Responses

  1. Nick says:

    HHHmmm Nope…

    “Permission denied”

    tried sudo !! and then run it.


    “permission denied”

  2. says:

    sync; echo 3 | sudo tee /proc/sys/vm/drop_caches


  3. Nick says:

    I knew that! LMAO Just testing 😉

  4. Nick says:

    Woh! It works! Why did I doubt it? 🙂

    Just saw the cache on my sys monitor disappear.

    Heh 🙂 System doesn’t like that, it’s building it again 🙂

    Thanks for that. Lovely!

  5. Nick says:

    Actually, on first glance I spotted the ‘>’ wondering why it feeding info into ‘/proc/sys/vm/drop_caches’.

    I need to question more maybe?

  6. says:

    In ” sudo echo 3 > /proc/sys/vm/drop_caches “, sudo is used to execute “echo 3” but redirection is made with current user.

    “tee” is used to redirect input directly to a file, so “sudo tee” user root rights to do it

  7. siva says:

    use root and execute the command .. sure it will work..
    by siva

  8. Punkd81 says:

    Works perfect!

  9. newguy says:

    i used gksudo instead of sudo like this sync; gksudo echo 3 > /proc/sys/vm/drop_caches and it worked for me

  10. enars says:

    $ sync; echo 3 | sudo tee /proc/sys/vm/drop_caches

    Excellent for desactivating Cache memory on ubuntu 1004-4 thanks

  11. enars says:

    I use ubuntu 1004-4 (on USB key only, it is slow, but quiet) , wine, winhttrack (websites downloader on windows XP) and my cache memory increased a lot. my computer became slowER and slowER, terrible!.
    I hope these exemples useful, under terminal :

    !!! BAD for me :
    a@a-USBK58:~$ sync; sudo echo 3 > /proc/sys/vm/drop_caches
    bash: /proc/sys/vm/drop_caches: Permission denied
    a@a-USBK58:~$ sudo sync; sudo echo 3 > /proc/sys/vm/drop_caches
    bash: /proc/sys/vm/drop_caches: Permission denied

    !!! BAD for me :
    aa@a-USBK58:~$ sync; gksudo echo 3 > /proc/sys/vm/drop_caches
    bash: /proc/sys/vm/drop_caches: Permission denied

    OK OK for me :
    a@a-USBK58:~$ sync; echo 3 | sudo tee /proc/sys/vm/drop_caches

    ALSO OK for me :
    (((( a@a-USBK58:~$ sudo swapoff -a )))) very useful so for desactivating swap (((swap is extremely slow if we only use ubuntu on a USB key )))

  12. James says:

    Can anyone please tell me what cron command I will add if I want to run this command every 15 hours? or daily onec?

  13. Rameen says:

    For those of you who are getting trouble w/ permission…

    You can use “sudo su” to go into “superuser” mode

    Then you should be able to run the command using sudo!

  14. working for me as root

  15. CGH says:

    Wow!, great command!

    works on Debian as well

  16. Muralidhara says:

    Thanks a lot. It worked!!!

  17. Akash Deep Gupta says:

    problem with this command is, sudo only work for sync not work for
    echo 3 > /proc/sys/vm/drop_caches so to run both command at a same time with sudo you must use
    like this
    sudo bash -c ‘sync; sudo echo 3 > /proc/sys/vm/drop_caches’

  18. Yes it’s works ! Thanks ! But how to set the command in crontab manager / the path ?

  19. Thanks,,, Perfect,,,

    Running this code : sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
    on Superuser / root.

    Clean caches.

  20. Jack says:

    Run this code for delete cache file

    sync; gksudo echo 3 > /proc/sys/vm/drop_caches
    it works…

Leave a Reply

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