How to check the disk usage on a Linux server

Checking disk usage on a Linux server is essential to ensure that your system has sufficient storage space for smooth operation. Here’s a step-by-step guide on how to monitor disk usage effectively:

1. Using the df command

The df (disk free) command provides a summary of the disk space usage on your server.

$ df -h

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   15G   30G  32% /
tmpfs           1.9G  1.3M  1.9G   1% /dev/shm
/dev/sdb1       100G   70G   30G  70% /data
  • Filesystem: The name of the disk or partition.
  • Size: Total space available on the disk.
  • Used: Space currently used on the disk.
  • Avail: Space available for use.
  • Use%: Percentage of disk used.
  • Mounted on: Directory where the filesystem is mounted.

2. Using the du command

The du (disk usage) command gives you detailed information about disk usage by individual directories and files.

$ du -sh /path/to/directory

1.5G    /path/to/directory

The -s option provides a summary, and the -h option makes the output human-readable.

To check the disk usage of all directories within a specified path:

$ du -h /path/to/directory

1.5G    /path/to/directory
1.0G    /path/to/directory/subdirectory1
500M    /path/to/directory/subdirectory2

3. Using lsblk for detailed information

The lsblk command lists all block devices, including partitions and their mount points.

$ lsblk

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0   50G  0 disk 
└─sda1   8:1    0   50G  0 part /
sdb      8:16   0  100G  0 disk 
└─sdb1   8:17   0  100G  0 part /data

This will provide detailed information on the available storage devices, their sizes, and mount points.

4. Using ncdu for an interactive approach

ncdu is a disk usage analyzer that provides an interactive interface to explore disk usage in a directory.

$ ncdu /path/to/directory

--- /path/to/directory -----------------------------------------
    1.5 GiB [##########] /subdirectory1
  500.0 MiB [###       ] /subdirectory2
    1.0 GiB [####      ] /subdirectory3
    2.0 GiB [##########] .

Install ncdu if it’s not already available:

$ sudo apt install ncdu   # For Debian/Ubuntu-based systems
$ sudo yum install ncdu   # For CentOS/Red Hat-based systems