Where are my inodes going?

My root filesystem is running out of inodes. If this were an issue of disk space, I’d use du -s to get a top-level overview of where the space is going, then head down the directory tree to find particular offenders. Is there an equivalent option for inodes?

The answers in this question will point out individual directories with high usage, but in my case, that’s no good: the Linux source directory, for example, gets scattered across 3000+ directories with low inode counts, rather than showing up as /usr/src/linux-4.0.5 52183.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

With GNU coreutils (Linux, Cygwin) since version 8.22, you can use du --inodes, as pointed out by lcd047.

If you don’t have recent GNU coreutils, and there are no hard links in the tree or you don’t care if they’re counted once per link, you can get the same numbers by filtering the output of find. If you want the equivalent of du -s, i.e. only toplevel directories, then all you need is to count the number of lines with each toplevel directory name. Assuming that there are no newlines in file names and that you only want non-dot directories in the current directory:

find */ | sed 's!/.*!!' | uniq -c

If you want to show output for all directories, with the count for each directory including its subdirectories, you need to perform some arithmetic.

find . -depth | awk '{
    # Count the current depth in the directory tree
    slashes = $0; gsub("[^/]", "", slashes); current_depth = length(slashes);
    # Zero out counts for directories we exited
    for (i = previous_depth; i <= current_depth; i++) counts[i] = 0;
    # Count 1 for us and all our parents
    for (i = 0; i <= current_depth; i++) ++counts[i];
    # We don´t know which are regular files and which are directories.
    # Non-directories will have a count of 1, and directories with a
    # count of 1 are boring, so print only counts above 1.
    if (counts[current_depth] > 1) printf "%dt%sn", counts[current_depth], $0;
    # Get ready for the next round
    previous_depth = current_depth;
}'


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x