Various ways to check disk usage on Linux

Various ways to check disk usage on Linux

Disk usage is an important aspect of managing any Linux system. It is necessary to monitor disk usage to ensure that there is enough space available for the operating system and applications. In this article, we will discuss various ways to check disk usage on Linux systems, with commands and examples of their results.

1. df Command

The df command is a commonly used tool to check disk space usage on Linux systems. It provides information about the file system disk space usage and is available on most Linux distributions. To use this command, open a terminal and type:

$ df -h

The ‘-h’ option will display the output in a human-readable format, which makes it easier to read. Here’s an example output:

Filesystem      Size  Used Avail Use% Mounted on
udev            7.8G     0  7.8G   0% /dev
tmpfs           1.6G  1.7M  1.6G   1% /run
/dev/sda1        40G   21G   17G  56% /
tmpfs           7.8G  250M  7.6G   4% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           7.8G     0  7.8G   0% /sys/fs/cgroup

This output displays the total size, used space, available space, and the percentage of disk space used. It also displays the file system name and the mount point.

2. du Command

The du command is used to estimate file space usage on a Linux system. It is used to find out the sizes of directories and files. To use this command, open a terminal and type:

$ du -h <directory or file name>

The ‘-h’ option displays the output in a human-readable format, which makes it easier to read. Here’s an example output:

2.2M    Downloads
4.0K    examples.desktop
1.1G    Documents
57M     Pictures
8.0K    Templates
24K     Videos
120K    Music
1.8M    Public

3. ncdu Command

The ncdu command is a disk usage analyzer tool that provides a graphical representation of disk usage on a Linux system. To use this command, open a terminal and type:

$ ncdu

This command will start the ncdu tool, which will display the disk usage information in a hierarchical manner, with the largest directories and files displayed first. Here’s an example output:

--- / ---------------------------------------------------------
    5.2 GiB [##########] /home
    1.6 GiB [####      ] /usr
  848.5 MiB [##        ] /var
  515.1 MiB [#         ] /lib
  274.6 MiB [          ] /boot
  132.8 MiB [          ] /opt
   88.5 MiB [          ] /etc
   16.7 MiB [          ] /bin
   11.4 MiB [          ] /sbin
   11.3 MiB [          ] /lib32
    9.9 MiB [          ] /lib64
    8.0 MiB [          ] /run
  

The full form of ncdu is “NCurses Disk Usage”.

ncdu is a disk usage analyzer tool that works by scanning the file system of a Linux system and calculating the sizes of directories and files. It provides a graphical representation of disk usage in a hierarchical manner, with the largest directories and files displayed first.

Internally, ncdu works by using the du command to scan the file system and calculate the sizes of directories and files. It then uses the NCurses library to create a graphical interface that displays the disk usage information in a hierarchical tree structure. The interface allows the user to navigate through the file system and drill down into directories to see their sizes and contents.

This Post Has One Comment

Leave a Reply