4

I am currently using Lubuntu 18.04

I thought that theese are the 3 right code lines to drop cache:

sync; echo 1 > /proc/sys/vm/drop_caches

sync; echo 2 > /proc/sys/vm/drop_caches

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

I've tried three all with and without sudo and the output is permission denied.

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

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

I have all windows closed, no applications running but still permission denied...

I am clearly doing something wrong, Could anyone tell me which is the right way to drop caches in Lubuntu?

Thanks in advance

ft18
  • 441
  • 2
    The problem is that > does not have sudo privilege, many people use echo 3 | sudo tee /proc/sys/vm/drop_caches to do the same job. – Alvin Liang Dec 07 '18 at 05:15

2 Answers2

7

Finally I found something that works...

sync

sudo sh -c "echo 1 > /proc/sys/vm/drop_caches"

sync

sudo sh -c "echo 2 > /proc/sys/vm/drop_caches"

sync

sudo sh -c "echo 3 > /proc/sys/vm/drop_caches"

And if you want to drop thumbnails make this:

rm -v -f ~/.cache/thumbnails/*/*.png ~/.thumbnails/*/*.png





 rm -v -f ~/.cache/thumbnails/*/*/*.png ~/.thumbnails/*/*/*.png

Of course you should use:

sudo apt clean
sudo apt autoclean

And that would be all... At least I thought so... but I may be wrong...

ft18
  • 441
3

The easiest way is with a script lifted here:

#!/bin/bash
if [[ $(id -u) -ne 0 ]] ; then echo "Please run as root" ; exit 1 ; fi
sync; echo 1 > /proc/sys/vm/drop_caches
sync; echo 2 > /proc/sys/vm/drop_caches
sync; echo 3 > /proc/sys/vm/drop_caches

Call the script drop-caches.

Mark it as executable using chmod a+x drop-caches

Call it using sudo ./drop-caches

If you place the script in /usr/local/bin you can call it using sudo drop-caches

  • How do I place the script from terminal? – ft18 Dec 04 '18 at 04:22
  • 1
    sudo -H leafpad /usr/local/bin/drop-caches I think. I haven't used Lubuntu in a while. After opening your editor, copy and paste the lines above into it. Save the file and follow the rest of the instructions above. – WinEunuuchs2Unix Dec 04 '18 at 04:43
  • Sorry doesn't work at all... Terminal close as enter the call if I enter the above and neither work creating the file with leafpad... sudo ./drop-caches makes an output command not found... – ft18 Dec 06 '18 at 01:57
  • 1
    sudo ./drop-caches implies it is in the current directory. In this case you would have to use cd /directory-name first. If you put the script in /usr/local/bin there is no need to use ./ prefix in front of script. Just use sudo drop-caches and because /usr/local/bin is already in the system's search path it will find the command automatically. The same thing happens when you type ls or cat or grep which are in the search path /usr/bin or something similar. – WinEunuuchs2Unix Dec 06 '18 at 03:36