Clearing OS Caches in Linux

Sometimes you want to run experiments on a cold cache. Instead of rebooting your PC, just echo a number to /proc/sys/vm/drop_caches.

$ echo 1 > /proc/sys/vm/drop_caches # To free pagecache
$ echo 2 > /proc/sys/vm/drop_caches # To free dentries and inodes
$ echo 3 > /proc/sys/vm/drop_caches # To free pagecache, dentries and inodes
As this is a non-destructive operation and dirty objects are not freeable, the user should run sync first. (Thanks to Sudarshan for the tip.)