Check Disk Usage in Linux: Commands & Practical Examples

Check Disk Usage in Linux: Commands and Practical Examples

Checking disk usage in Linux helps you monitor available storage, identify large directories, and prevent your server from running out of disk space. Whether you manage a Linux VPS, dedicated server, or desktop system, commands such as df, du, and find make it easier to understand how storage is being used.

In this guide, you’ll learn how to check available disk space, measure directory sizes, find large files, monitor inode usage, and troubleshoot common disk-space problems using practical Linux commands.

Check Available Disk Space Using the df Command

1. Check Available Disk Space Using the df Command

The df command (disk free) displays used and available space across mounted filesystems.

Run:

df -h

The -h option displays storage values in a human-readable format, such as GB and MB.

Example output:

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda1        80G   45G   31G  60% /

/dev/sda2       200G  120G   70G  64% /home

tmpfs           2.0G     0  2.0G   0% /dev/shm

Understanding the output:

  • Filesystem: The storage device or filesystem.
  • Size: Total filesystem capacity.
  • Used: Space currently in use.
  • Avail: Available storage space.
  • Use%: Percentage of used storage.
  • Mounted on: Directory where the filesystem is mounted.

Other useful df commands include:

df -h /

Check available space on the root filesystem.

df -h /home

Check the filesystem containing the /home directory.

df -hT

Display filesystem types along with disk usage.

These commands are particularly useful when monitoring storage on Linux VPS and dedicated servers.

Check Directory Size Using the du Command

2. Check Directory Size Using the du Command

While df displays filesystem-level storage information, the du command (disk usage) estimates how much space individual directories and files consume.

To check the total size of a directory, run:

du -sh /var

Here:

  • -s displays a summary instead of listing every subdirectory.
  • -h displays sizes in a human-readable format.

To check the size of your current directory:

du -sh .

To check the sizes of visible files and directories in the current location:

du -sh *

Important: The * wildcard normally excludes hidden files and directories. To include hidden entries as well, you can use:

du -sh .[^.]* *

You can also check specific directories:

du -sh /var/log

du -sh /home

du -sh /var/www

These commands help identify which areas of a Linux server are consuming storage.

3. Find the Largest Directories in Linux

If your server is running low on disk space, identifying large directories is an important first step.

Use:

du -h –max-depth=1 /var

This displays the sizes of directories directly inside /var, without listing every nested directory.

To sort the results by size:

du -h –max-depth=1 /var | sort -hr

To display the ten largest directories:

du -h –max-depth=1 /var | sort -hr | head -10

To investigate the root filesystem while avoiding other mounted filesystems, run:

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

The options mean:

  • -x: Stay within the same filesystem.
  • -h: Display readable storage values.
  • -d1: Show one directory level.
  • sudo: Allow access to directories requiring administrative permissions.
  • 2>/dev/null: Suppress permission and other error messages.

Note: The –max-depth and -d options are supported by GNU du, commonly available on Linux distributions.

This method is useful for investigating storage-heavy locations such as /var, /home, /usr, and /var/lib.

4. Find Large Files in Linux

Sometimes a single large file consumes a significant amount of disk space. The Linux find command can locate files based on their size.

To find files larger than 100 MB:

find / -type f -size +100M 2>/dev/null

To find files larger than 1 GB:

find / -type f -size +1G 2>/dev/null

To search for large files inside a specific directory:

find /var -type f -size +100M 2>/dev/null

To display file sizes in a readable format:

find /var -type f -size +100M -exec ls -lh {} \; 2>/dev/null

Common reasons for large files include:

  • Old backup archives.
  • System and application log files.
  • Database backups.
  • Website media and uploaded files.
  • Temporary files and downloaded archives.

Review files before deleting them, particularly on production servers. A large file may be required by an application or system process.

5. Check Disk Usage by Inodes

Linux filesystems use inodes to store file metadata, including ownership, permissions, timestamps, and references to file data. Directory entries associate filenames with inode numbers.

A filesystem can run out of available inodes even when it still has free disk space. This can prevent applications from creating new files.

To check inode usage, run:

df -i

Example output:

Filesystem     Inodes  IUsed  IFree IUse% Mounted on

/dev/sda1     5000000 450000 4550000    9% /

Important columns include:

  • Inodes: Total available inodes.
  • IUsed: Inodes currently in use.
  • IFree: Remaining available inodes.
  • IUse%: Percentage of used inodes.

If inode usage reaches 100%, investigate directories containing large numbers of small files, such as cache folders, temporary files, and application sessions.

View Disk Partitions Using the lsblk Command

6. View Disk Partitions Using the lsblk Command

The lsblk command displays information about block devices, including disks, partitions, and mount points.

Run:

lsblk

For more detailed filesystem information:

lsblk -f

This displays information such as:

  • Device names.
  • Partition structure.
  • Filesystem types.
  • UUIDs.
  • Mount points.

The command is useful for understanding how storage devices and partitions are arranged on your Linux server.

Important: lsblk shows the storage-device layout, not the actual used and available space within filesystems. Use df -h for filesystem usage.

7. Analyze Disk Usage Interactively Using ncdu

If you prefer an interactive way to inspect storage, ncdu (NCurses Disk Usage) is a useful command-line utility.

It allows you to navigate directories and identify which folders consume the most space.

On Ubuntu or Debian, install it using:

sudo apt update

sudo apt install ncdu

On RHEL-based systems where the package is available in an enabled repository:

sudo dnf install ncdu

Start scanning the root filesystem:

sudo ncdu -x /

You can navigate through directories using your keyboard and inspect their sizes.

Note: ncdu can also delete files through its interface. Review selections carefully and avoid removing system files, application data, or production backups without understanding their purpose.

8. Why Do df and du Show Different Disk Usage?

Sometimes Linux administrators notice that df -h reports significantly more used disk space than the total shown by du.

This happens because both commands measure storage differently.

  • df reports overall filesystem space usage.
  • du estimates space consumed by files and directories that it can access.

Several situations can cause different results.

Deleted files still held open

A deleted file may continue consuming disk space if a running process still has it open. Although the file no longer appears in its directory, the process continues referencing its data.

To identify deleted files that are still open, use:

sudo lsof +L1

If lsof is installed, this command can help identify processes holding deleted files.

After identifying the responsible process, investigate whether restarting the relevant service or process is appropriate. Do not terminate production services without considering their impact.

Other possible reasons include:

  • Filesystem metadata and reserved filesystem blocks.
  • Mounted filesystems hiding underlying directory contents.
  • Files that cannot be accessed because of permissions.
  • Differences between allocated disk space and apparent file sizes.
  • Filesystem-specific storage allocation and compression behavior.

When investigating a disk-space problem, compare df -h and du results and check for deleted-open files before assuming that storage is missing.

9. Quick Linux Disk Usage Check for VPS Administrators

If you manage a Linux VPS or dedicated server, these commands provide a useful starting point for checking storage consumption.

# Check available disk space

df -h

# Check inode availability

df -i

# Find the largest directories

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

# Find files larger than 500 MB

sudo find / -xdev -type f -size +500M 2>/dev/null

# Check for deleted files still held open

sudo lsof +L1

These commands help you identify filesystem usage, inode limitations, large directories, oversized files, and deleted files that may still occupy storage.

Some commands may take time to complete on large servers, especially when scanning the entire filesystem.

10. What to Do When Linux Disk Space Is Almost Full

If your Linux server is running low on storage, identify the source of the problem before removing anything.

Common areas worth investigating include:

Directory What to investigate
/var/log System and application logs
/var/cache Cached application and package data
/home User files and backups
/var/lib Application and database data
Website directories Uploaded files, archives, and backups

Before removing files:

  1. Identify the directories or files consuming the most space.
  2. Confirm whether the files are still required.
  3. Check whether valid backups exist.
  4. Review application and system dependencies.
  5. Remove or archive only files that are safe to delete.

Avoid deleting files directly from system directories simply because they are large. This can cause application failures, data loss, or server instability.

If storage remains insufficient, consider reviewing your VPS storage allocation and planning an appropriate storage expansion.

Frequently Asked Questions

The df -h command checks used and available disk space across mounted filesystems. To check individual directory sizes, use du -sh.

Run:

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

This displays the largest directories at the root level, with the largest ones appearing first.

df reports used and available space at the filesystem level, while du estimates the storage consumed by files and directories. Their results may differ because they measure different aspects of storage usage.

Run:

df -i

This displays the total, used, and available inodes for mounted filesystems.

A deleted file may still occupy disk space if a running process has it open. Use sudo lsof +L1 to identify deleted files that are still being held by processes.

Conclusion

Monitoring disk usage is an important part of Linux server administration. Commands such as df, du, find, lsblk, and ncdu help you understand storage consumption and identify potential problems.

For routine checks, start with df -h to review available space and use du to investigate directory sizes. If storage usage appears unusually high, inspect large files, inode consumption, and deleted files still held open by running processes.

Regular disk-space checks can help you identify storage problems early and keep your Linux server running smoothly.

The author
Asher Feroze

I’m Asher Feroze, and I’ve been part of CreativeON for several years, working in various roles including Manager Operations, Business Development Manager, and technical support for our web hosting services. Over time, I’ve gained deep insights into both the business and technical sides of the industry. Now, I use that experience to write informative articles for CreativeON, Gworkspace, and gworkspacepartner.pk, helping readers make smart choices when it comes to web hosting and Google Workspace solutions.

Table of Contents