Clean cache to reclaim memory without a reboot

Tip submitted by my friend J.K when we were in need of a way to recover reserved cache space without booting.


In root:

PageCache only:

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

Dentries and inodes:

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

PageCache, Dentries and inodes:
(not recommanded in production as it forces a full cache rebuilt. you may still need it):

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

In case you need to do it in a sudo:

echo 3 | sudo tee /proc/sys/vm/drop_caches