Is it possible to get a Live Inode Count?

So, a couple of days ago, I saw a inode limit warning. The inode counter on Cpanel was red, and said that I had used up 34894 of 30019. I then deleted some installed themes, some plugins, and got the inode count down to 76%. But, since the inode counter in Cpanel isn’t updated live, I wanted to know how I can find the inode count. Is there some way to view the live count? Like, in ftp, or can I download the website and check the inode count?

Wait 24hrs for it to be updated

Updating the inode count isn’t done live because it basically involves traversing your entire website to count the files and directories.

But you can do it yourself through PHP. If you create a PHP file in your htdocs directory, you can put the following contents into it:

<?php

set_time_limit(0);

$directory = new RecursiveDirectoryIterator('./');

$counters = [];

foreach ($directory as $item) {
    if (!is_dir($item)) {
        continue;
    }

    $parts = explode('/', $item);
    $basename = end($parts);

    if (strpos($basename, '.') === 0) {
        continue;
    }

    $itemIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($item));
    $counters[(string) $item] = iterator_count($itemIterator);
}

arsort($counters);

foreach ($counters as $path => $count) {
    echo $path.': '.$count.'<br/>'.PHP_EOL;
}

echo "Total: ".array_sum($counters);

If you then trigger this script from the browser, it will tell you the inode count of the folder right now.

Due to security restrictions on free hosting, you can only do this per website folder, not for the entire account. But it may give you some indication.

7 Likes

Oh. Thank You.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.