Candid photograph of a Linux server terminal with a soft olive-green glow against a dark slate background, conveying a calm technical atmosphere.

Step-by-step guides for system administrators — covering command-line basics, web server setup, and preparation material for technical interviews.

Browse Tutorials

Using du and df to Analyze Disk Space Usage on RHEL

Disk space problems on Red Hat Enterprise Linux often appear first as failed package updates, slow applications, or services that refuse to write logs. The du and df commands provide two different views of storage: du measures directory and file usage, while df reports available capacity on mounted filesystems.

This distinction matters on servers hosted in Australian cloud regions such as Sydney or Melbourne, where a full root filesystem can affect websites, databases, and monitoring systems at the same time. The following commands work well on RHEL, CentOS Stream, and Fedora systems managed from locations such as Brisbane or Perth.

Command Measures Best use
du -sh /path Files and directories Finding large folders
du -xhd1 / Directory totals on one filesystem Locating top-level growth
df -h Filesystem capacity Checking free and used space
df -i Inodes Detecting too many small files
lsof +L1 Open, deleted files Finding space held by processes

Understanding Filesystem Usage

The df command asks the filesystem how many blocks are used and available. By contrast, du walks through visible directory entries and adds their sizes. The numbers can differ because of filesystem metadata, reserved blocks, sparse files, mount points, and files that have been deleted while a process still has them open.

Start with a readable summary:

df -hT

The -h option uses human-readable units, while -T displays the filesystem type. Pay particular attention to /, /var, /home, and any separate mount used for application data. Administrators building broader Linux skills can find related Linux administration guides for filesystem, service, and command-line work.

Finding Large Directories With du

To inspect the root filesystem without descending into mounted filesystems, run:

sudo du -xhd1 / 2>/dev/null | sort -h

The -x option keeps the scan on the same filesystem, -d1 limits the output to one directory level, and sort -h places sizes in a useful order. If /var is the largest result, inspect it with:

sudo du -xhd1 /var 2>/dev/null | sort -h

Common sources of growth include /var/log, /var/cache/dnf, container storage, web application uploads, and database directories. Use du -sh for a single path, but remember that access permissions may require sudo.

Reading df Accurately

A typical df result includes total blocks, used blocks, available blocks, percentage used, and the mount point. A filesystem showing 90 percent usage deserves investigation before it reaches 100 percent. Some services need working space even when a small amount remains available.

Check inode consumption separately:

df -ih

A filesystem can have free gigabytes but no free inodes if it contains millions of small files. Mail queues, PHP session files, temporary uploads, and monitoring data can cause this condition. This is relevant to busy Australian retail and finance platforms, where high transaction volumes may generate large numbers of short-lived files during local business hours.

Explaining Differences Between du and df

When df reports far more used space than du, check for deleted files still held open by a running process:

sudo lsof +L1

A log file removed with rm still consumes blocks until its owning process closes the file. Restarting the responsible service usually releases the space, but verify the service name and operational impact before doing so.

Mount points can create another apparent mismatch. A recursive du / scan may include other filesystems, while df reports each mount independently. Use du -x for a like-for-like comparison, and inspect bind mounts, NFS mounts, and container overlay filesystems separately.

Cleaning Space Safely

Avoid deleting files solely because they are large. First identify their owner, purpose, and retention requirements. For systemd journal data, inspect usage with:

journalctl --disk-usage

A controlled cleanup can remove entries older than a defined period:

sudo journalctl --vacuum-time=14d

For DNF metadata and cached packages, review the cache before cleaning:

sudo du -sh /var/cache/dnf
sudo dnf clean all

Log rotation should normally be managed through logrotate, not manual deletion. Check its configuration under /etc/logrotate.conf and /etc/logrotate.d/. Before changing production data, preserve required records and follow the retention rules used by your organisation or Australian regulatory environment. Practical storage safety practices can also help reinforce the importance of backups and controlled deletion.

Automating Regular Checks

A short command can expose files larger than 500 MB:

sudo find /var -xdev -type f -size +500M -printf '%s %p\n' \
  2>/dev/null | sort -n

For routine monitoring, combine df with a threshold test:

df -P / | awk 'NR==2 {gsub("%","",$5); if ($5 >= 80)
  print "Warning: root filesystem is", $5 "% full"}'

Run checks from cron, systemd timers, or an existing monitoring platform. Consider different thresholds for production and development systems, and account for Australian time zones when correlating growth with scheduled backups, overnight batch jobs, or Melbourne and Sydney trading workloads.

These commands are also common in technical screening and Linux operations assessments. Reviewing Linux interview questions is useful when you need to explain why du and df disagree, how inode exhaustion differs from block exhaustion, or why an unlinked file can continue consuming disk space.

A practical workflow is to run df -hT first, check df -ih when necessary, then use du -xhd1 to locate the largest directory. Confirm suspicious files with lsof +L1, clean only verified targets, and record the result so the next disk-space alert has a clear starting point.