Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to free Inode usage on Linux?
The inode (also known as index node) is a data structure that stores metadata about files and directories in Linux file systems. Each file or directory uses one inode, which contains information like permissions, ownership, timestamps, and pointers to data blocks. When inodes are exhausted, you cannot create new files even if disk space is available.
Checking Inode Usage
You can check the inode usage on your system using the df command with the -i option −
df -i
This displays inode information for all mounted filesystems −
Filesystem Inodes IUsed IFree IUse% Mounted on /dev/sda1 30523392 125843 30397549 1% / /dev/sda2 6553600 2048 6551552 1% /home tmpfs 506234 1 506233 1% /dev/shm
The IUse% column shows the percentage of inodes used. If this reaches 100%, you cannot create new files regardless of available disk space.
Finding Directories with High Inode Usage
To identify which directories consume the most inodes, use this command to check root-level directories −
for d in /*; do echo "$d: $(find "$d" -type f 2>/dev/null | wc -l) files"; done 2>/dev/null | sort -k2 -nr
For a specific directory, you can get detailed inode usage −
find /var -type f | cut -d"/" -f1-3 | sort | uniq -c | sort -nr | head -10
Common Methods to Free Inodes
Remove Old Package Files
Clean up old kernel headers and unused packages −
sudo apt autoremove --purge sudo apt autoclean
Remove specific old kernel versions −
sudo apt-get remove linux-headers-5.4.0-42 sudo apt-get remove linux-image-5.4.0-42-generic
Clean Temporary Files
Remove temporary files that may be consuming inodes −
sudo find /tmp -type f -atime +7 -delete sudo find /var/tmp -type f -atime +7 -delete
Clean Log Files
Large log directories often contain many small files −
sudo find /var/log -type f -name "*.log.*" -mtime +30 -delete sudo journalctl --vacuum-time=30d
Advanced Inode Analysis
For detailed analysis of inode usage by directory −
sudo find / -xdev -type f | cut -d"/" -f2 | sort | uniq -c | sort -nr | head -10
This command shows which top-level directories contain the most files.
Verifying Results
After cleanup, verify the inode usage has decreased −
df -i
Filesystem Inodes IUsed IFree IUse% Mounted on /dev/sda1 30523392 98432 30424960 1% / /dev/sda2 6553600 1847 6551753 1% /home tmpfs 506234 1 506233 1% /dev/shm
The IUsed count should be lower and IUse% should decrease, indicating successful inode cleanup.
Conclusion
Freeing inode usage involves identifying directories with excessive small files and removing unnecessary data like old kernels, temporary files, and logs. Regular maintenance prevents inode exhaustion and ensures your system can continue creating new files effectively.
