Sort directories by number of files contained

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: