Q:

Permission for all commands, but unable to clear cache

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.

A:

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

