Find which directory is using most inodes

Oneliners to find which directory on the server is using most inodes:

To find how many inodes are used per each directory on certain path run:

find ./ -maxdepth 1 -type d -print0 | while IFS= read -r -d $'\0' dir; do echo "$(find "$dir" | wc -l) "$dir""; done| sort -n | tail

Last line will show the path being searched and second to last line will be directory with most inodes, then cd to that directory and run again to see which subfolder is using most inodes.

To get directory with most inodes immediately, without the need to cd in each directory you can run following:

find ./ -type d -print0 | while IFS= read -r -d $'\0' dir; do echo "$(stat -t "$dir" | awk '{print$2}') "$dir""; done | sort -n | tail

This will not show the number of inodes used, only which directory has most inodes in it.
Oneliner from top can be used to get exact number of inodes in it.

One thought on “Find which directory is using most inodes”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.