How to Clear Cache in Linux

It should be much more safer to sync the data to disk before clear the caches.

sync

1) Clear PageCache only.

echo 1 > /proc/sys/vm/drop_caches

2) Clear dentries and inodes.

echo 2 > /proc/sys/vm/drop_caches

3) Clear PageCache, dentries and inodes.

echo 3 > /proc/sys/vm/drop_caches