0

I am trying to clear the cache on my laptop running:

Operating System: Ubuntu 20.04 LTS
          Kernel: Linux 5.4.0-40-generic

However when I put in these commands this is the output:

$ sudo sync; echo 1 > /proc/sys/vm/drop_caches
bash: /proc/sys/vm/drop_caches: Permission denied
$ sudo sync; echo 2 > /proc/sys/vm/drop_caches
bash: /proc/sys/vm/drop_caches: Permission denied
$ sudo sync; echo 3 > /proc/sys/vm/drop_caches
bash: /proc/sys/vm/drop_caches: Permission denied

However when checking my permissions I get this:

$ sudo -l
Matching Defaults entries for [MY USERNAME] on [COMPUTER NAME]:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User [MY USERNAME] may run the following commands on [COMPUTER NAME]:
    (ALL : ALL) ALL

It would appear that I can run all commands. Why is this happening, and is there a fix?

I have also replicated the issue in root.

  • Related: [How to solve “permission denied” when using sudo with redirection in Bash?](https://askubuntu.com/questions/230476/how-to-solve-permission-denied-when-using-sudo-with-redirection-in-bash) – steeldriver Jul 03 '20 at 19:15

1 Answers1

2

You are running sync with sudo, but not the shell's redirection of the echo. Instead do:

sudo sh -c 'sync; echo 1 > /proc/sys/vm/drop_caches'

or

sudo sync; echo 1 | sudo tee /proc/sys/vm/drop_caches >/dev/null
steeldriver
  • 131,985
  • 21
  • 239
  • 326
P.P
  • 1,021
  • 8
  • 17