Introduction

In Linux, an inode is a data structure that stores information about a file or directory, such as its permissions, ownership, timestamps, and disk block locations. Every file and directory consumes one inode. Even if sufficient disk space is available, a filesystem can become unusable when all available inodes are exhausted.

The following shell command helps identify the number of inodes (files and directories) used within each subdirectory of the current directory. This is particularly useful when troubleshooting Disk Quota issues on cPanel servers or identifying directories consuming an unusually high number of inodes.


Prerequisites

Before running the command, ensure the following:

  • SSH access to the Linux/cPanel server.
  • A user account with permission to access the target directory.
  • Basic knowledge of Linux command-line operations.
  • Standard Linux utilities such as find, cut, grep, sort, wc, and printf must be available (installed by default on most Linux distributions).

Steps to Calculate Inode Usage

Step 1: Connect to the Server

Log in to the server using SSH.

ssh username@server-ip

Step 2: Navigate to the Target Directory

Move to the directory whose inode usage you want to analyze.

Example:

cd /home/username

Step 3: Run the Inode Usage Command

Execute the following command:

printf "===\nInode usage :$(pwd)\n===\n\n"; \
for i in `find -maxdepth 1 -type d | cut -d '/' -f2 | grep -xv . | sort`; do
    tot=$(find "$i" | wc -l)
    printf "$tot\t\t -> $i\n"
done
printf "Total:\t\t $(find "$(pwd)" | wc -l)\n"

Step 4: Review the Output

Example output:

===
Inode usage : /home/username
===

1050         -> public_html
425          -> mail
120          -> logs
35           -> tmp

Total:       1630

Output Explanation:

  • Each line shows the total number of files and directories (inode count) within a subdirectory.
  • The Total value represents the overall inode usage for the current directory.
  • Directories with significantly higher counts may require cleanup if inode limits are being reached.

Conclusion

This command provides a quick way to identify directories consuming the highest number of inodes on a Linux or cPanel server. It is particularly useful when troubleshooting inode quota issues, locating directories with excessive files, and planning cleanup activities to prevent inode exhaustion. Regularly monitoring inode usage helps maintain server performance and ensures efficient filesystem management.

Leave a Reply