Inodes
Notes for checking inode usage and safely freeing inodes on Linux/RHEL systems.
Use this page when a filesystem reports No space left on device, but normal disk usage still shows free space.
What is an inode?
An inode stores metadata about a file or directory.
It contains information such as:
file type
permissions
owner
group
size
timestamps
data block locations
Simple idea:
filename -> inode -> file metadata and data location
A filesystem needs a free inode to create a new file.
Why inodes matter
A filesystem can run out of inodes even when there is still free disk space.
This often happens when there are many small files.
Example problem:
Application cannot create new files.
Command shows: No space left on device.
df -h still shows free space.
In that case, check inode usage.
Check normal disk usage
df -h
This shows normal disk space usage.
Check inode usage
df -i
Important columns:
IUsed = used inodes
IFree = free inodes
IUse% = inode usage percentage
Example:
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/example 100000 99000 1000 99% /var
If IUse% is very high, the filesystem may be running out of inodes.
Common causes of inode exhaustion
many small log files
application cache files
temporary files
session files
mail queue files
monitoring files
old spool files
bad script creating files in a loop
application bug
First command set
df -h
df -i
findmnt
lsblk
Then investigate the affected filesystem.
Find where many files are located
Example for /var:
sudo find /var -xdev -type f | sed 's#/[^/]*$##' | sort | uniq -c | sort -n | tail
Example for /opt:
sudo find /opt -xdev -type f | sed 's#/[^/]*$##' | sort | uniq -c | sort -n | tail
This helps show which directories contain many files.
Count files in a directory
find /path/to/directory -type f | wc -l
Example:
find /opt -type f | wc -l
List old files before deleting
Always list files first before deleting.
Example: list files under /opt older than 5 days:
find /opt -type f -mtime +5 -ls
This does not delete anything.
Use this first to review which files may be candidates for housekeeping.
Housekeeping workflow
Use this flow before deleting files:
1. Confirm inode issue with df -i.
2. Identify the affected filesystem.
3. Find directories with many files.
4. List old files first.
5. Review the output.
6. Pick only files that are safe to housekeep.
7. Delete only after confirming they are safe.
8. Verify inode usage again.
Example: investigate /opt
Check inode and disk usage:
df -h
df -i
Check what filesystem /opt belongs to:
findmnt /opt
List old files under /opt older than 5 days:
find /opt -type f -mtime +5 -ls
Review the list carefully.
Only after confirming the files are safe to remove, choose the correct housekeeping action.
Safer review method
Save the list to a file first:
find /opt -type f -mtime +5 -ls > /tmp/opt-files-older-than-5-days.txt
Review:
less /tmp/opt-files-older-than-5-days.txt
Count:
wc -l /tmp/opt-files-older-than-5-days.txt
This helps avoid deleting blindly.
Find old files by directory
If you already know the affected directory:
find /path/to/directory -type f -mtime +5 -ls
Example:
find /opt/app/cache -type f -mtime +5 -ls
Review before deleting.
Safe delete old files
Only after confirming the files are safe to remove:
sudo find /path/to/directory -type f -mtime +5 -delete
Example:
sudo find /opt/app/cache -type f -mtime +5 -delete
Verify:
df -i
Important: test first without -delete.
Safer delete with a reviewed list
Create a list:
sudo find /path/to/directory -type f -mtime +5 > /tmp/files-to-housekeep.txt
Review:
head /tmp/files-to-housekeep.txt
tail /tmp/files-to-housekeep.txt
wc -l /tmp/files-to-housekeep.txt
Delete only after review:
sudo xargs -r rm -f < /tmp/files-to-housekeep.txt
Verify:
df -i
Delete empty directories
After deleting many files, remove empty directories if safe:
sudo find /path/to/directory -type d -empty -delete
Verify:
df -i
Clean package cache
If the inode issue is package/cache related, use package tools instead of manual deletion.
RHEL/DNF:
sudo dnf clean all
Verify:
df -i
df -h
Clean temporary files
List old temporary files first:
sudo find /tmp -xdev -type f -mtime +7 -ls
sudo find /var/tmp -xdev -type f -mtime +30 -ls
Delete only if safe:
sudo find /tmp -xdev -type f -mtime +7 -delete
sudo find /var/tmp -xdev -type f -mtime +30 -delete
Verify:
df -i
Important warning about logs
Do not delete active log files blindly.
If a service is writing to a log file, deleting the file may not free disk space until the service is restarted.
For logs, prefer log rotation.
Check log directories:
sudo du -sh /var/log/*
sudo find /var/log -xdev -type f | wc -l
List old compressed logs:
sudo find /var/log -xdev -type f -name "*.gz" -mtime +30 -ls
Delete old compressed logs only if allowed:
sudo find /var/log -xdev -type f -name "*.gz" -mtime +30 -delete
Fix the cause
Freeing inodes is only a temporary fix if something keeps creating files.
After cleanup, check again later:
df -i
Questions to ask:
Which process or application created many files?
Is log rotation working?
Is a cache cleanup job missing?
Is a script creating files in a loop?
Is a mail queue or spool stuck?
Is an application bug creating too many temporary files?
Should a scheduled housekeeping job be created?
Safe cleanup checklist
1. Confirm inode usage with df -i.
2. Find the directory with many files.
3. Check what kind of files they are.
4. List old files first with find ... -ls.
5. Review examples with less/head/tail.
6. Count files before deleting.
7. Delete only files that are safe to remove.
8. Verify with df -i.
9. Fix the cause so it does not happen again.
Dangerous commands
Be very careful with:
rm -rf /path
find /path -delete
find /path -exec rm -f {} \;
Never run delete commands on /, /etc, /usr, /var, /home, /opt, or application data without understanding exactly what will be removed.
Always test first without -delete.
Example issue
Problem:
Application cannot create new files.
df -h shows free space.
Check:
df -i
Finding:
Filesystem has 100% inode usage.
List old files:
find /opt -type f -mtime +5 -ls
Action:
Review the listed files.
Pick only files that are safe to housekeep.
Delete only after confirming they are not needed.
Verify:
df -i
Notes
Running out of inodes is different from running out of disk space.
Use:
df -h
for disk space.
Use:
df -i
for inode usage.