Linux empty buffer cache command permission denied
10,612
Solution 1
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)
Solution 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:
- You're doing this operation too quickly
- There is nothing to empty since you just previously ran the command
- Your previous command hasn't had a chance to complete or be processed
References
Related videos on Youtube
![Mina Hafzalla](https://i.stack.imgur.com/OJnpj.jpg?s=256&g=1)
Author by
Mina Hafzalla
Updated on September 18, 2022Comments
-
Mina Hafzalla almost 2 years
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?
-
Security Beast over 9 yearsjust for improvement in me may i know y this got depreciated
-
jasonwryan over 7 yearsThis adds nothing to the existing answers other than the fact it is not in English...
-
heemayl over 7 yearsAlso whats the point of
sudo
beforeecho
? -
G-Man Says 'Reinstate Monica' over 7 yearsUnix & 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.