Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I run a free -m, I get this output:

Free -m output

Is there a command that I could use to clear the used memory? I have tried this:

echo 1 > /proc/sys/vm/drop_caches

It will ask for sudo. But even after sudo, it gives bad command error.

Here is the link where I got to know about drop_caches.

I am just looking for a way on how to clear the cache.

share|improve this question

migrated from Sep 5 '12 at 3:30

This question came from our site for professional and enthusiast programmers.

Off topic. Belongs to superuser. Voting to close. – Macmade Sep 2 '12 at 3:33
Why are you asking?? It is usually not worth the effort! – Basile Starynkevitch Sep 2 '12 at 7:42
I want to test the performance of an application , which initiates several processes , and generate some statistics , If i run the same application for two times the statistics will not be accurate , and also clear understanding of how the application behaves in each of scenarios , will remain as a mystery . If cache is the matter for its performance , I definitely need to know if there is any way there to clear the cache so that I can take care of it . I am really sorry , If this stack overflow is not a platform to ask such system level questions . – aravind.udayashankara Sep 2 '12 at 16:43
up vote 8 down vote accepted

Try this as root (not sudo):

#sync && echo 3 > /proc/sys/vm/drop_caches
share|improve this answer

The problem with:

sudo echo 1 > /proc/sys/vm/drop_caches

is that the redirect happens in the initial shell - i.e. under your own account - before the "sudo echo 1" happens, which isn't the part that really needs root access. You need to get the opening of drop_caches by ">" to be inside of the sudo. One lazy way (lazy because it clones the 3 back to stdout, which you don't actually need) is:

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

The options to write into drop_caches are:

  1. Free pagecache
  2. Free dentries and inodes
  3. Free pagecache, dentries, and inodes.

And you should sync first, so all in all:

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

or if you don't like the spurious "3" on stdout:

sudo sh -c 'sync ; echo 3 >/prod/sys/vm/drop_caches'
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .