How to Check Disk Space in Linux?

Learn via video courses
Topics Covered

Introduction

Checking disk space in Linux is essential for managing storage resources and ensuring optimal system performance. By monitoring disk space, you can identify potential issues, such as high utilization, and take necessary actions to free up space or allocate additional storage. In this FAQ, we'll explore various methods and find out how to check disk space in Linux.

Prerequisites

Before checking disk space in Linux, ensure that you have access to a Linux system and its terminal to run the commands mentioned in this guide. Familiarity with basic Linux terminal commands will also be helpful.

Causes of High Disk Space Utilization

Depending on the system and user behaviors, different factors can contribute to high disk space utilization in Linux. Here are a few common reasons:

  • Large Files and Directories: Large files can quickly fill up disk space, including videos, virtual machine images, and database backups. Similar to downloads, log folders can also contribute to excessive disk space utilization by accumulating a large number of files.

  • System logs: Over time, system logs generated by different services and applications can build up and take up a lot of disk space. These logs might eat up valuable storage if log rotation and cleanup processes are not correctly configured.

  • Installations of new software and packages: Installing new software and packages frequently need more disk space. A high disk space utilization can be caused by temporary files that some apps create after installation and fail to erase.

  • Unmanaged databases: Database systems like MySQL can produce huge data files that take up a lot of disk space. High disk space utilization can result from ineffective database administration, which may include failing to periodically delete outdated information or failing to optimize the database size.

  • System Backups: This can take up a lot of disk space, especially if they are often made or kept for a long time. Inadequate rotation or compression in backup systems can result in high disk space consumption.

  • User Files and Personal Data: Users storing large media files, documents, or other personal data on their systems can contribute to high disk space utilization. The amount of disk space available can be considerably impacted by individual usage behavior and file storage habits.

  • Temporary Files: These files are created by a variety of programs during operation. Examples include caches, temporary downloads, and temporary installation files. These temporary files might build up and take up disk space if they are not periodically removed.

  • System misconfiguration: Inefficient disk space utilization may result from incorrect configuration of programs, services, or file systems. For instance, improperly configured log rotation settings might cause logs to expand forever and take up enormous amounts of disk space.

  • Hidden Files and Directories: Although hidden files and directories with a dot (.) are commonly overlooked, they nonetheless take up space on the hard drive. Applications frequently use these files to store their settings and configurations.

Monitoring disk usage often, identifying the biggest contributors, and taking appropriate measures are necessary to control high disk space utilization. Next, Let's find out how to check disk space in Linux.

Check Free Disk Space Using Linux Terminal Commands

Let's find out some of the most useful command line utilities to check disk space in Linux.

1. df Command

The "df" command is a commonly used command in Unix-based operating systems, such as Linux, to display information about the disk space usage of file systems. It is a convenient way to check the available space, used space, and overall capacity of mounted file systems on your system. An example mentioned below helps check disk space in Linux.

"df" stands for "disk free" and is the primary command used to retrieve disk space information.

df command

2. du Command

The "du" command is a valuable tool for monitoring disk usage, identifying space-consuming files or directories, and optimizing storage utilization. It provides insight into how disk space is allocated, allowing system administrators to manage their storage resources effectively.

This above-mentioned command will help check disk space in Linux and display the summarized disk usage for the specified directory.

du command

3. ls -al Command

The "ls -al" command provides a comprehensive and detailed view of the files and directories within a specified directory. It is particularly useful for tasks such as examining file permissions, identifying ownership, checking file sizes, and viewing the most recent modification times.

Let's break down the components of the "ls -al" command:

  • "ls" stands for "list" and is the primary command used to list files and directories.

  • "-a" is an optional flag that stands for "all." When used, it displays all files, including hidden files that start with a dot (.), which are typically not shown in regular directory listings.

  • "-l" is another optional flag that stands for "long." When used, it presents a detailed, long format listing for each file and directory.

When you execute the "ls -al" command in a terminal within a specific directory, it retrieves and displays Permissions, Number of Links, Owner, Group, File Size, Date and Time, and Name which helps check disk space in Linux.

ls -al command

4. stat Command

The "stat" command provides a powerful way to gather in-depth information about files and directories. It is commonly used for tasks such as file analysis, monitoring file attributes, and script automation. It retrieves and displays various attributes and metadata associated with a given file or directory, including file type, permissions, size, timestamps, and more.

The basic syntax of the "stat" command is as follows:

The above-mentioned command is shown as an example of the "stat" Command which helps check disk space in Linux.

stat command

5. fdisk -l Command

The "fdisk -l" command provides a quick overview of the disk partitioning scheme on the system. It allows you to identify the available disk devices and understand how they are partitioned, including the size and type of each partition. This information is particularly useful for system administration tasks, disk management, and troubleshooting.

This command provides detailed information about the partition layout, including the partition type, size, and starting and ending sectors, and helps check disk space in Linux.

fdisk -l command

6. btrfs fi df /device/ Command

The "btrfs fi df /device/" command is used to display the disk space usage of a specific Btrfs filesystem residing on a particular device. Btrfs is a modern file system available in Linux that offers advanced features such as snapshots, data checksums, and efficient storage management.

Here's a breakdown of the components of the "btrfs fi df /device/" command:

  • "btrfs" refers to the command-line tool for managing Btrfs filesystems.

  • "fi" is short for "filesystem" and is used to specify that the following command is related to filesystem operations.

  • "df" stands for "disk free" and is a subcommand of the "btrfs" tool that retrieves disk space information.

  • "/device/" represents the path or device associated with the Btrfs filesystem you want to analyze. It could be something like "/dev/sda1" or a mount point like "/mnt/btrfs".

Check Free Disk Space Graphically

Graphical tools make it easier to check disk space. Let's find out two inbuilt GUI Disk Space Checkers in Linux.

Disk Usage Analyzer Tool

The Disk Usage Analyzer tool offers details on the size, percentage of disk space occupied by, and number of items in each directory and file. It enables you to efficiently manage your storage, find areas with high disk utilization, and help check disk space in Linux.

disk usuage analyzer tool

Disk

A graphical application called Disk, commonly referred to as GNOME Disk Utility, is available in GNOME desktop environments and offers disk management and analysis features. You can use it to see and control your file systems, disk drives, and partitions. It offers crucial capabilities for monitoring, maintaining, and troubleshooting disks. By typing "disks" into your GNOME desktop environment's application launcher, you can find GNOME disks.

disk

Learn More

To learn more about Linux file systems and Disk management, check out the links given below.

File System of Linux

Memory and Disk Management in Linux

Conclusion

  • Checking disk space in Linux is crucial for efficient system management.

  • By utilizing various terminal commands like df, du, ls -al, stat, and fdisk -l, you can obtain disk space utilization information.

  • Additionally, graphical tools offer a user-friendly way to monitor disk space.

  • Regularly monitoring disk space helps in preventing storage-related issues and ensures smooth system operation.