Old logs filling disk? How to find hidden files and inodes
Learn how to audit disk space consumed by old logs by combining shell scripts and advanced scanning utilities to free exhausted inodes.
Summary
- Inode exhaustion happens when the file system runs out of file identifiers, even while physical disk space appears abundant.
- Traditional commands like du can fail to map open files held by frozen processes that continue consuming disk storage.
- Scanning with advanced command-line utilities allows engineers to isolate bulky directories efficiently without production impact.
- Shell scripts automate periodic scans and safe log purging without introducing operational risks or downtime.
- Continuous inode monitoring prevents sudden critical service outages caused by running out of free file pointers.
Why does the disk say it is full when space is free?
Who has never experienced the frustration of receiving a disk-full alert, deleting gigabytes of files, and discovering that the system remains frozen or complaining about missing space? Most of the time, the culprit is not the data volume itself, but the exhaustion of so-called inodes. In practice, an inode is like a file registry card in the operating system: it stores vital information such as permissions, owner, and physical data location, but not the file content itself. When millions of tiny log files are created, we can exhaust all available registry cards in the partition long before the physical space in bytes runs out. To avoid surprises in production environments, it is also essential to understand infrastructure optimization, such as handling scenarios when infrastructure metrics go offline and require fast service recovery.
How to audit actual consumption using command-line tools
When the issue is physical space consumed by piles of old logs, the standard command tends to be du, a utility that estimates file and directory space usage. However, du can be misleading when dealing with files that were deleted by the operating system but remain open and running under a hung process. In practice, this means disk space remains occupied because the OS keeps the file pointer active in memory. To inspect these ghost files and prevent them from overflowing storage, many engineers use network data streaming techniques, such as streaming heavy compressed files via SSH without filling up local disk space. Combining precise scans with zombie process identification ensures no hidden area escapes the audit.
Developing a shell script for scanning and safe cleanup
To automate the hunt for old logs and lost inodes, we can write a robust and secure shell script. The script below traverses specific directories, identifies files older than thirty days, and displays detailed usage before any removal takes place. In practice, automation prevents human errors caused by fatigue during late-night manual operations. Here is how to structure the search and cleanup procedure on your machine:
#!/bin/bash
# Target directory for log auditing
TARGET_DIR="/var/log/old_apps"
echo "Starting scan for files older than 30 days in $TARGET_DIR..."
find "$TARGET_DIR" -type f -mtime +30 -exec ls -lh {} \; | awk '{print $5, $9}'
echo "Checking remaining inodes in the partition..."
df -i "$TARGET_DIR"
Running this kind of routine frequently helps keep server health in check, ensuring the operating system responds smoothly even under heavy log writing workloads. Furthermore, keeping servers operating at proper temperatures, making sure server racks do not suffer from overheating and poor airflow, complements the physical stability of the infrastructure.
Best practices to prevent future inode and space exhaustion
Auditing old logs is an excellent remedy, but establishing preventive policies is the true key to peace in system administration. The best strategy involves implementing automatic log rotation through native tools like logrotate, which compresses and discards old files on a scheduled basis. In practice, this prevents a single application from creating millions of uncontrolled micro-files over the months. Combining periodic audit scripts with automated alerts for exhausted inodes transforms a reactive, stressful operation into a predictable, secure, and fully controlled process.