Inode usage on Linux is checked with the `df -i` command, which shows available and used inodes per filesystem. Knowing how to check inode in linux is essential for system administrators and developers who need to monitor disk space and file system health. Inodes store metadata about files, and running out of them can cause errors even if there’s free disk space.
This guide covers multiple methods to check inodes, interpret the output, and troubleshoot common issues. You’ll learn command-line tools, GUI alternatives, and practical tips for managing inode usage.
What Is An Inode In Linux?
An inode (index node) is a data structure that stores information about a file or directory except its name and actual data. Each file on a Linux filesystem has a unique inode number. Inodes contain metadata like permissions, ownership, timestamps, and pointers to data blocks.
Think of inodes as file IDs. When you create a file, the system assigns an inode. The filesystem has a fixed number of inodes created during formatting. Once all inodes are used, you cannot create new files, even if disk space remains.
Why Checking Inodes Matters
Running out of inodes is a common issue on systems with many small files, such as mail servers, cache directories, or application logs. Symptoms include “No space left on device” errors despite free disk space. Regular inode checks help prevent unexpected outages.
- Inode exhaustion stops file creation
- Mail servers with many small emails are vulnerable
- Temporary directories with millions of cache files
- Backup systems with numerous incremental files
How To Check Inode In Linux Using Command Line
The primary method to check inode usage is the `df` command. Let’s explore detailed usage with examples.
Using `Df -I` To View Inode Statistics
The `df -i` command displays inode information for all mounted filesystems. Run it without sudo to see your current usage.
df -i
Output shows filesystem, inodes total, used, free, use percentage, and mount point. Example:
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda1 655360 123456 531904 19% /
tmpfs 1024005 12 1023993 1% /dev/shm
Focus on the IUse% column. Values near 100% indicate potential problems. The IFree column shows remaining inodes.
Checking Specific Filesystem Inodes
To check a particular mount point, add the path:
df -i /var
This shows inode stats only for the /var filesystem. Useful when monitoring specific partitions.
Human Readable Output With `-H`
Combine `-i` with `-h` for easier reading:
df -ih
This displays sizes in KB, MB, or GB. However, inode counts remain absolute numbers, not human-readable sizes.
Checking Inodes For A Specific Directory
Sometimes you need to know how many inodes a directory uses. The `find` command with `-printf` option works well.
Count Files In A Directory
To count all files (including subdirectories) in /var/log:
find /var/log -type f | wc -l
This shows total file count, which equals inode usage for regular files. Directories also use inodes, so add `-type d` for a complete picture.
Using `Stat` To Check A Single File’s Inode
The `stat` command shows detailed inode information for a specific file:
stat filename.txt
Output includes Inode number, permissions, size, and timestamps. Example:
File: filename.txt
Size: 1024 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 1234567 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ user) Gid: ( 1000/ group)
List Inode Numbers With `Ls -I`
The `ls -i` command shows inode numbers for files in a directory:
ls -i /etc
Each line starts with the inode number. Useful for identifying hard links or duplicate inodes.
Understanding Inode Limits And Filesystem Types
Different filesystems handle inodes differently. Ext4 creates a fixed number during formatting, while XFS and Btrfs allocate them dynamically.
Ext4 Inode Limits
Ext4 sets inode count based on filesystem size and inode_ratio (default 16384 bytes per inode). A 100GB partition gets about 6.5 million inodes. You can check with:
dumpe2fs -h /dev/sda1 | grep 'Inode count'
XFS Dynamic Inodes
XFS allocates inodes on demand, so you rarely run out. However, metadata space is limited. Check XFS inode usage with:
xfs_info /mount/point
Btrfs And ZFS
Btrfs and ZFS also use dynamic inode allocation. They don’t have a fixed limit, but metadata space can still fill up.
Common Scenarios Where Inodes Run Out
Understanding when inode exhaustion occurs helps you prevent it. Here are typical situations.
Mail Servers With Many Small Emails
Each email is a separate file. A busy mail server can create millions of files quickly. Check /var/spool/mail or /home/*/Maildir.
Application Cache Directories
Web caches, session files, and temporary files accumulate. Directories like /tmp, /var/cache, or application-specific caches.
Log Files Without Rotation
If log rotation is disabled, log files grow and create many small log files. Check /var/log for excessive files.
Backup Systems With Incremental Files
Incremental backups create many small files. Over time, inode usage spikes.
How To Fix Inode Exhaustion
When inodes are full, you cannot create new files. Here’s how to recover.
Find And Delete Unnecessary Files
Use `find` to locate files older than 30 days in a problematic directory:
find /var/log -type f -mtime +30 -delete
Be careful with `-delete`; test with `-print` first.
Use `Xargs` For Bulk Deletion
For directories with millions of files, use `xargs` to avoid argument list too long errors:
find /tmp -type f -name '*.tmp' -print0 | xargs -0 rm -f
Reformat The Filesystem With More Inodes
If you frequently run out, reformat with a smaller inode_ratio. For ext4:
mkfs.ext4 -i 8192 /dev/sdX
This doubles the inode count. Backup data first.
Monitor Inode Usage Proactively
Set up cron jobs to check inode usage and alert you. Example script:
#!/bin/bash
THRESHOLD=90
df -i | awk 'NR>1 {if ($5+0 > THRESHOLD) print $0}'
Using Graphical Tools To Check Inodes
For desktop users, GUI tools offer visual inode monitoring.
GNOME Disks Utility
Open Disks, select a partition, and click the gear icon. Choose “Filesystem” to see inode usage. Not all versions show inodes.
GParted
GParted shows inode count for ext filesystems. Select partition and view “Used” and “Unused” inodes in the information panel.
System Monitor
Some system monitors like `htop` or `glances` display inode usage. Install `glances` and run it:
glances
Press ‘1’ to see per-filesystem details including inodes.
Automating Inode Checks With Scripts
Create a simple bash script to check inode usage across all filesystems.
#!/bin/bash
echo "Inode Usage Report - $(date)"
df -i | awk 'NR>1 {print $1, $5}'
Save as `check_inodes.sh`, make executable with `chmod +x`, and run periodically via cron.
Advanced Script With Alerts
This script sends an email if any filesystem exceeds 80% inode usage:
#!/bin/bash
THRESHOLD=80
df -i | awk -v thresh=$THRESHOLD 'NR>1 {if ($5+0 > thresh) print $0}' | mail -s "Inode Alert" admin@example.com
Understanding Inode Numbers And Hard Links
Hard links share the same inode. When you create a hard link, the inode count increases, but no new inode is used. This is why deleting one hard link doesn’t free the inode until all links are removed.
Find Hard Links
Use `find` with `-samefile` to locate hard links:
find / -samefile /path/to/file
Or check link count with `stat`.
Inode Numbers And File Deletion
When you delete a file, the inode is freed only if no hard links remain. Use `ls -l` to see link count (second column).
Troubleshooting Inode Related Errors
Common error messages and their solutions.
“No Space Left On Device” With Free Disk Space
Run `df -i` to confirm inode exhaustion. Delete old files or increase inode count.
“Too Many Open Files” Error
This is a file descriptor limit, not inodes. Check with `ulimit -n`. Increase system-wide limits in /etc/security/limits.conf.
“Disk Quota Exceeded”
Quotas can limit inode usage. Check with `quota -u username`. Adjust quotas if needed.
Best Practices For Inode Management
Follow these tips to avoid inode problems.
- Monitor inode usage weekly with `df -i`
- Set up log rotation to prevent file accumulation
- Use filesystems with dynamic inodes (XFS, Btrfs) for high-file-count workloads
- Keep temporary directories clean with cron jobs
- Archive old data to reduce file count
- Use `tmpwatch` or `tmpreaper` to auto-delete old temp files
Comparing Inode Checking Tools
Here’s a quick comparison of tools discussed.
| Tool | Purpose | Example |
|---|---|---|
| df -i | Filesystem inode summary | df -i /home |
| stat | Single file inode details | stat file.txt |
| ls -i | List inode numbers | ls -i /etc |
| find | Count files in directory | find /dir -type f | wc -l |
| dumpe2fs | Ext filesystem inode count | dumpe2fs -h /dev/sda1 |
Frequently Asked Questions
What Happens When Inodes Run Out?
You cannot create new files or directories. Existing files can still be read, written, or deleted. The system may report “No space left on device” even with free disk space.
How Can I Check Inode Usage For A Specific User?
Use `find /home/username -type f | wc -l` to count files owned by that user. For quota-based limits, use `quota -u username`.
Can I Increase Inode Count Without Reformatting?
Not easily. For ext4, you can’t increase inodes after creation. You must backup, reformat with more inodes, and restore. XFS and Btrfs don’t have fixed limits.
What’s The Difference Between Inodes And Disk Blocks?
Inodes store metadata (permissions, timestamps, pointers). Disk blocks store actual file data. Running out of inodes prevents new file creation; running out of blocks prevents writing data.
How Do I Check Inode Usage In Real-time?
Use `watch -n 1 df -i` to refresh every second. Or use `glances` for a live dashboard with inode info.
Conclusion
Knowing how to check inode in linux is a fundamental skill for managing file systems. The `df -i` command gives you a quick overview, while `stat` and `ls -i` provide file-level details. Regular monitoring prevents unexpected outages from inode exhaustion.
Remember that different filesystems handle inodes differently. Ext4 has fixed limits, while XFS and Btrfs are more flexible. For systems with many small files, consider using dynamic inode filesystems or increasing the inode count during formatting.
By following the best practices outlined here—monitoring, cleaning temp files, and setting up alerts—you can keep your Linux system running smoothly without inode-related issues. Start by running `df -i` right now to check your current inode usage.