Sort directories by number of files contained

Sat, 2009-05-09

Here is a one-liner which sorts all the directories under ‘/’ by the number of files contained:

find / -type d -exec sh -c 'ls -a1 "$1" | wc -l' \"{}\" {} \; -print | \
sed  '$!N;s/\n/ /' | sort -gr

I recently needed this on a linux server where the inode quota was exceeded. Through the one-liner I discovered where most of the inodes where consumed.


Turn off regular expression search in less

Tue, 2008-10-14

You can disable regular expression search in less by hitting ctrl+r after you have hit /

Very handy when searching for character like $, *, [, ], …