1

I'm using the following commands to flush cache:

# sync; echo 3 > /proc/sys/vm/drop_caches
# sync; echo 2 > /proc/sys/vm/drop_caches
# sync; echo 1 > /proc/sys/vm/drop_caches

When I use one of the above commands, I get the following:

-bash: /proc/sys/vm/drop_caches: Permission denied

My system running CentOS 6.5, I logged in as root via SSH.

Any suggestions?

Mina Hafzalla
  • 181
  • 2
  • 2
  • 7

4 Answers4

2

I'm not sure why are you're running the 3 commands, when the first one is all you need:

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

This will do the following 3 things: free pagecache, dentries and inodes. Using 1 only frees the pagecache while 2 frees the dentries + inodes.

You're probably experiencing some weird timing issue where:

  1. You're doing this operation too quickly
  2. There is nothing to empty since you just previously ran the command
  3. Your previous command hasn't had a chance to complete or be processed

References

slm
  • 363,520
  • 117
  • 767
  • 871
2

this one should work regardless the linux distribution you are running. You need to cover the redirection when running sudo.

$ sudo sh -c "$(which echo) 3 > /proc/sys/vm/drop_caches"

Credits: https://unix.stackexchange.com/a/148442/101951 (i added the which echo part though)

thebugfinder
  • 121
  • 1
  • 1
  • 3
-1

Simply you should try this

echo 3 > /proc/sys/vm/drop_caches

but you one is also working with me Same situation here but works fine [root@I-IDS ~]# w 20:56:35 up 4:03, 2 users, load average: 0.00, 0.00, 0.11 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root tty4 - 16:55 3:48m 0.25s 0.25s -bash root pts/0 192.168.1.42 20:55 0.00s 0.20s 0.00s w [root@I-IDS ~]# cat /etc/redhat-release CentOS release 6.5 (Final) [root@I-IDS ~]# sy sync sysctl sys-unconfig
[root@I-IDS ~]# sync; echo 3 > /proc/sys/vm/drop_caches [root@I-IDS ~]# sync; echo 2 > /proc/sys/vm/drop_caches [root@I-IDS ~]# sync; echo 1 > /proc/sys/vm/drop_caches [root@I-IDS ~]# sync; echo 3 > /proc/sys/vm/drop_caches

can you please post our teminal output here from entering command to output

Security Beast
  • 892
  • 7
  • 14
-2

Use:

echo 3 | sudo tee /proc/sys/vm/drop_caches
  • This adds nothing to the existing answers other than the fact it is not in English... – jasonwryan Nov 07 '16 at 04:49
  • 1
    Also whats the point of `sudo` before `echo`? – heemayl Nov 07 '16 at 04:50
  • 1
    Unix & Linux Stack Exchange is an English-only site, and all the questions and answers are expected to be in English. But also, “Try this” followed by a command is not an answer. If you’re just guessing, don’t post an answer. If you’re sure that this is a correct answer, explain why it works.  Answers without explanations are subject to deletion. – G-Man Says 'Reinstate Monica' Nov 07 '16 at 04:56