The Linux kernel automatically frees up memory by dropping stale data and caches to maintain optimal performance. Manual cache clearing is rarely necessary, but when needed, it can be done with a few simple commands.


# Flush dirty buffers to disk before dropping caches
sync
# Clear PageCache only
echo 1 | sudo tee /proc/sys/vm/drop_caches
# Clear dentries and inodes
echo 2 | sudo tee /proc/sys/vm/drop_caches
# Clear PageCache, dentries, and inodes
echo 3 | sudo tee /proc/sys/vm/drop_caches

# Safe one-liner to clear all caches
sync; sudo tee /proc/sys/vm/drop_caches <<< 3