How to Check Disk Space in Linux

If you’ve been using Linux for a while, you probably know that disk space management is essential for system performance and stability. However, checking disk space in Linux is not as complicated as you might think. This article will explore different ways to check disk space in Linux, ranging from simple command-line tools to advanced graphical utilities.

Using the df command to check disk space in Linux

The df command is a built-in Linux utility that displays information about the filesystems currently mounted in the system. Here’s an example:

ShellScript
$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        20G  4.1G   15G  22% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
/dev/sdb1        50G   12G   38G  24% /mnt/data

The output shows each filesystem’s total size, used space, available space, and usage percentage. In addition, the -h option displays the measures in a human-readable format.

Using the du command to check disk space usage in Linux

The du command is another built-in Linux utility that displays the disk space used by files and directories. Here’s an example:

ShellScript
$ du -h /var/log
  10M   /var/log/cups
  15M   /var/log/apt
  4.0K  /var/log/sysstat
  64M   /var/log

In the output, you can see the size of each file and directory within /var/log. The -h option displays the sizes in a human-readable format.

Checking disk space with graphical tools in Linux

Several utilities allow you to check disk space usage if you prefer a graphical user interface (GUI). For example, GNOME Disks and KDE Partition Manager are popular options. Here’s an example of using GNOME Disks:

  • First, open the Disks application from your application menu.
  • Next, click on the disk you want to check in the left pane.
  • The right pane will display information about the disk, including the amount of free space.

Checking disk space remotely in Linux with SSH

If you need to check disk space on a remote Linux system, you can use SSH to connect to the system and run commands. Here’s an example:

ShellScript
$ ssh user@remote-host "df -h /"
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        20G  4.1G   15G  22% /

In the output, you can see the disk space usage of the root filesystem on the remote-host system.

Automating disk space monitoring with cron and shell scripts

If you want to automate checking disk space, you can use cron and shell scripts. Here’s an example of a shell script that checks the disk space usage of the /var directory:

ShellScript
#!/bin/bash

THRESHOLD=90
PARTITION=/dev/sda1

df -h $PARTITION | tail -n 1 | awk '{print $5}' | sed 's/%//g' | while read usage; do
  if [ $usage -ge $THRESHOLD ]; then
    echo "Disk space usage is above threshold: $usage%"
  fi
done

In the script, the THRESHOLD variable specifies the usage threshold at which an alert should be triggered. The PARTITION variable specifies the partition.

FAQ on How to Check Disk Space in Linux

Question 1: What is disk space?

Disk space is the storage capacity available on your computer’s hard drive. It is where your operating system, applications, and personal files are stored.

Question 2: Why should I check disk space in Linux?

Checking disk space in Linux is important because if your hard drive runs out of space, your system may slow down or even crash. It is also important to monitor disk space to ensure you have enough space for new files and software installations.

Question 3: How do I check disk space in Linux?

You can check your disk space using the “df” command in the Linux terminal. Simply open the terminal and type “df -h” to see a list of available drives and their disk space usage.

Question 4: What does the “df” command output mean?

The “df” command output shows the total size of the disk, the amount of disk space used, the amount of disk space available, and the percentage of disk space used. It also shows the mount point or the location where the drive is mounted in the file system.

Question 5: How often should I check disk space in Linux?

It is a good practice to periodically check disk space in Linux, especially if you frequently install new software or download large files. You can set up automated disk space monitoring using tools like Nagios, Munin, or Zabbix to receive alerts when your disk space usage reaches a certain threshold.

Want to learn more Linux facts? Check out the rest of our Tech Quicky content!!
Elsewhere On TurboGeek:  How to Install Mediawiki on a Ubuntu

Richard.Bailey

Richard Bailey, a seasoned tech enthusiast, combines a passion for innovation with a knack for simplifying complex concepts. With over a decade in the industry, he's pioneered transformative solutions, blending creativity with technical prowess. An avid writer, Richard's articles resonate with readers, offering insightful perspectives that bridge the gap between technology and everyday life. His commitment to excellence and tireless pursuit of knowledge continues to inspire and shape the tech landscape.

You may also like...

2 Responses

  1. 08/10/2023

    […] to remove a directory (rmdir) and its contents for various reasons, such as freeing up space or cleaning up your file system. However, removing a directory in Linux is not as straightforward as deleting a file. There are […]

  2. 30/01/2024

    […] Need to Free Up Disk Space on Linux Server or Desktop? You’ve come to the right place. Perhaps you have seen our other article about how to check disk space on Linux. […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Translate ยป