Fedora

How to Check Free and Used Space on Fedora Linux

This guide showcases how to check the free and used disk spaces on Fedora Linux.

Prerequisites:

To perform the steps that are demonstrated in this guide, you need the following components:

  • A properly-configured Fedora Linux system. If you don’t have one, you can work with a Fedora Linux VM instead.
  • A suitable terminal emulator. Check out some of the finest terminal emulators for Linux.
  • Access to a non-root user with sudo privilege.

Disk Storage in Fedora Linux

Linux comes with a robust framework for handling the various hardware devices including storage devices. The storage devices are also known as block devices. It refers to how the Linux kernel interfaces with the hardware by referencing the fixed-size blocks.

The devices that are included in this category are HDDs, SSDs, USB flash drives, memory cards, and such. Any new device that is connected to the system is treated as a part of the existing filesystem tree. With the proper permission, you can perform the read/write operations.

Checking the Disk Usage in Fedora Linux

Each block device comes with a limited storage space. So, it’s paramount to make the most of it. Keeping an eye on the usage of the storage capacity can provide hints on better optimization and storage allocation.

By default, Linux comes with a handful of tools to check the amount of the occupied storage space. There are also some robust third-party apps that you can use.

Using the Df Command

The “df” command is a part of the built-in tools that Linux comes with. It reports the available space on the filesystem.

If it is run without any argument, the output is as follows:

$ df

The output shows the size in number of blocks (1 block = 1 kilobyte). To get a human-readable format, use the following command instead:

$ df -h

If no filesystem is specified, “df” reports the available space on the entire filesystem tree. If you know the partition label, you can use the following command instead:

$ df -h <partition>

A quick way of checking the available storage spaces is to specify the root partition:

$ df -h /

Another interesting feature of “df” is to display the info about filesystems based on their types. For example, to list all the “ext4” filesystems and report their free space, use the following command:

$ df -h -t ext4

Using the Du Command

Similar to “df”, the “du” command is a part of the pre-installed tools that most Linux distros come with. However, it reports different stats than “df”. Rather than the amount of free space, “du” reports the amount of the used storage space.

Without any parameter, “du” returns the total space that is occupied by the current location:

$ du

If a location is specified, it returns a super-detailed report like this:

$ du /var/log

By default, the file sizes are described in blocks. To get the units in human-readable format, use the following command:

$ du -h

Certain device capacity is calculated as 1000 bytes = 1 kilobyte instead of 1024 bytes = 1 kilobyte. The storage capacity of HDDs is common for such measurement. To enforce the 1000-byte unit, use the following command:

$ du -H /var/log

The default behavior of “du” is to print the size and the directory as a list. If you’re interested in just the total storage space that is occupied by the specific directory, use the following command instead:

$ du -hs <dir_location>

The “du” command can also work with individual files:

$ du -h <file_location>

The next technique takes advantage of Bash scripting. Check it out:

$ while sleep 1;do du -h <location>;done

Here:

  • It’s a single line Bash script.
  • Each iteration of the while loop pauses for 1 second before running the next iteration.
  • The result is a live log that showcases how the filesystem is being filled up. It can be useful when working with a program/script with extensive logging.

Check out the Bash programming category for more tricks.

Using GParted

Besides the command-line tools, there are also robust GUI tools like GParted that we can use to check the amount of the used storage space. It can be installed on the system itself or you can get a live CD/USB.

To install GParted on Fedora Linux, run the following command:

$ sudo dnf install gparted

Once installed, launch it from the menu:

From the top-right corner, you can choose the storage device to spectate. GParted shows all the partitions on the device along with the amount of storage that is used in each partition.

Disk Space Management

Partitioning is a common practice to distribute the disk space to various programs and users. The physical storage is divided into multiple virtual sections, each section acting as if it is a unique storage device. Learn more about partitioning using fdisk and GParted.

Various virtualization programs use LVM (Logical Volume Management) to manage the disk space allocation to various VMs. Rather than physically creating/deleting/resizing new partitions, logical partitions are easier to manage. It also supports additional features like encryption, snapshots, and such. Learn more about configuring and using LVM on CentOS/Fedora.

Conclusion

We demonstrated the various ways of checking the disk space usage on Fedora Linux. We showcased how to check the amount of free and used spaces of a storage device using “du”, “df”, and various other GUI tools. We also briefly discussed how to manage the disk space using partitioning.

About the author

Sidratul Muntaha

Student of CSE. I love Linux and playing with tech and gadgets. I use both Ubuntu and Linux Mint.