Disk space management is an essential part of maintaining a stable Linux system. When storage becomes full, applications may fail to write data, logs can stop recording important information, and in extreme cases the system itself can become unstable.

For system administrators and developers, regularly checking disk usage helps avoid unexpected outages and keeps servers running smoothly. Linux provides several built-in commands that allow you to monitor storage usage, identify large files, and clean up unnecessary data.

In this guide, you’ll learn the most useful commands to check disk space in Linux and how to use them effectively.

Understanding Disk Space Monitoring in Linux

Linux offers multiple tools to analyze storage usage. The two most commonly used commands are:

  • df (disk free) – Shows overall disk usage for mounted filesystems.
  • du (disk usage) – Displays the size of specific directories and files.

Typically, you begin with df to determine whether a disk is nearing capacity. If it is, you then use du to locate the directories consuming the most storage.

Check Disk Space in Linux Using the df Command

The df command provides a quick summary of disk usage for all mounted filesystems.

Running the command without options displays sizes in blocks, which can be difficult to read. Adding the -h option makes the output human-readable.

df -h

The output generally includes:

  • Filesystem name
  • Total disk size
  • Used space
  • Available space
  • Usage percentage
  • Mount location

This command is often the first step when troubleshooting storage issues.

Check Inode Usage

In some cases, a system may run out of inodes even when disk space is still available. Inodes store metadata about files, and if they are exhausted, the system cannot create new files.

You can check inode usage with:

df -i -h

If the inode usage reaches 100%, new files cannot be created until unused files are removed.

Check Directory Size Using the du Command

While df shows overall disk usage, du helps determine which directories or files are consuming space.

To check the size of a specific directory:

du -sh /var/log

Options used:

  • -s – Shows only the summary
  • -h – Displays sizes in human-readable format

If you want to see the size of directories within a parent folder:

du -h --max-depth=1 /var

This approach helps quickly identify which top-level directories are using the most disk space.

Analyze Disk Usage with ncdu

For a more user-friendly experience, you can use ncdu, an interactive disk usage analyzer.

It provides a navigable interface directly inside the terminal, allowing you to quickly find large files.

Installation example (Debian/Ubuntu):

sudo apt install ncdu

Run it like this:

ncdu /

You can browse directories using arrow keys and even delete files directly from the interface.

Use pydf for a More Readable Disk Overview

pydf is a Python-based alternative to the standard df command. It presents filesystem usage with improved formatting and color highlighting.

Install it with:

sudo apt install pydf

Then run:

pydf

This can make it easier to spot filesystems that are close to full.

Use duf for a Modern Disk Usage Overview

A more modern alternative to df is duf, a fast disk usage tool written in Go that provides a cleaner and more colorful output.

It automatically adjusts to terminal width and groups devices by type, making it easier to understand disk usage at a glance.

Install it using:

sudo apt install duf

Run the command:

duf

You can also check specific locations:

duf /home /data

Many system administrators prefer duf because of its clear layout and improved readability.

View Disk Devices with lsblk

The lsblk command lists all block devices connected to your system, including disks, partitions, and logical volumes.

Run:

lsblk

The output appears as a tree structure that shows how disks and partitions are organized and where they are mounted.

This command is helpful when managing multiple drives or virtual disks on servers.

Inspect File Details with stat

If you need detailed information about a specific file, the stat command can help.

Example:

stat filename

This command displays:

  • File size
  • Disk blocks used
  • Access permissions
  • Last access and modification times

It’s particularly useful when investigating individual files that might be consuming unexpected space.

Combining Commands for Better Disk Analysis

Linux becomes extremely powerful when commands are combined together.

Here are a few useful combinations.

Find the Largest Files or Directories

You can identify large directories by combining du, sort, and head.

du -h /var | sort -rh | head -n 10

This command lists the 10 largest directories inside /var.

Ignore Specific File Types

Sometimes you want to calculate storage usage but exclude certain file types.

Example:

du -sh --exclude="*.zip" /home/user

This command lists the 10 largest directories inside /var.

Locate Files Larger Than a Specific Size

The find command can search for files based on their size.

Example:

find /var/log -type f -size +100M

This finds all files larger than 100 MB inside /var/log.

This technique is useful for identifying oversized logs or backups.

Find the Largest Files on the System

When disk space suddenly becomes full, identifying the largest files on the system can help locate the source of the problem.

You can search the entire system for very large files using:

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

This command scans the filesystem for files larger than 500 MB, sorts them by size, and displays the 10 largest files. It is a useful way to quickly locate large logs, backups, or temporary files that may be consuming disk space.

Check cPanel Backup Usage

On servers running cPanel, backups are a common reason for disk space issues. Full account backups and automated backup archives can accumulate over time and consume a significant amount of storage.

You can quickly check the size of the backup directory with:

du -sh /backup

This command displays the total size of the /backup directory in a human-readable format. If backups are using excessive space, consider removing older backups or adjusting your backup retention settings.

Check Disk Usage on Container Systems

If your server runs Docker or other container platforms, disk usage can grow quickly because container images and volumes are stored locally.

To check Docker storage usage, run:

docker system df

Most container data is typically stored in:

/var/lib/docker

If disk space issues occur on container hosts, this directory should be checked first.

Check Systemd Journal Log Usage

On systems using systemd, journal logs can accumulate over time and consume a significant amount of disk space.

You can check how much disk space the journal is using with:

journalctl --disk-usage

If the logs are using too much storage, you can clean up older entries by running:

journalctl --vacuum-size=500M

This command keeps the journal size under 500 MB by removing older log entries while preserving recent ones.

Frequently Asked Questions

What is the difference between df and du?

  • df shows disk usage at the filesystem level.
  • du measures the storage used by directories or files.

Use df to check overall disk capacity and du to locate space-consuming files.

Why does df show more usage than du?

Sometimes deleted files remain open by running processes. In this situation, the disk space remains allocated even though the file is no longer visible.

You can identify such files with:

sudo lsof +L1 | grep deleted

Which directories should I check first when disk space is full?

Common locations that grow quickly include:

  • /var/log
  • /tmp
  • /var/tmp
  • /home

Logs and temporary files are often responsible for sudden disk usage spikes.

How Can I Safely Clean Up Disk Space?

Instead of manually deleting important system files, it is best to start with safe cleanup methods that remove temporary data, old packages, or unnecessary logs. Linux provides several built-in tools that help free up disk space without affecting system stability.

Clean Log Files Safely

Logs can grow quickly, especially on busy servers. Instead of deleting log files, it is better to use log rotation tools such as logrotate, which automatically compress and remove older logs.

If you need to clear a large log file manually without deleting it, you can truncate it:

sudo truncate -s 0 /var/log/large.log

Alternatively:

sudo > /var/log/large.log

These commands clear the contents of the file while keeping the log file itself intact.

Clean Package Cache

Package managers store downloaded packages locally, which can accumulate over time and consume disk space.

For Ubuntu / Debian systems:

sudo apt clean

For RHEL, AlmaLinux, or Rocky Linux:

sudo dnf clean all

This removes cached package files that are no longer needed.

Remove Old Kernels and Unused Packages

Old kernels and unused dependencies may remain installed after system updates. Removing them can free up additional disk space.

For Ubuntu / Debian systems:

sudo apt autoremove

These commands remove unused packages and outdated dependencies that are no longer required by the system.

Conclusion

Monitoring disk space regularly is essential for keeping Linux systems stable and responsive. By using commands such as df, du, ncdu, lsblk, and modern tools like duf, you can quickly identify storage issues and take action before they affect your applications.

Combining these tools with commands like sort and find gives you a powerful way to analyze disk usage and locate unnecessary files.

With proper monitoring and maintenance, you can ensure your Linux server continues running efficiently without unexpected storage problems.

If you need assistance with server management or infrastructure solutions, feel free to reach out to our team at sales@netrouting.com  we’re happy to help.

Need help?

Find answers quick, talk to us on live chat.

Start Live Chat
support-chat-bottom
Phone
+31(0)88-045-4600
+1-305-705-6983
Table of Contents