Sometimes users need to check free and consumed disk space to perform daily tasks and system management. For example, users may experience problems when installing software or storing new information due to a lack of free disk space, Or for any reason, users need to check the disk space. Some of them may not even know how to check the free disk space and this issue becomes a challenge for them.
Since the usage of the Linux operating system has recently become more common than other operating systems among users and developers, our article is allocated to checking the free disk space in the Linux system to manage the disk space better and get the desired result from Linux system performance.
Today, various graphical tools provide helpful information about the amount of disk usage in Linux, but not all tools can meet the needs of Linux desktop users. Therefore, the safest and easiest way to check the disk space is through the Linux command line, which provides users with all the information they need.
The two commands, df and du are commands that provide users with comprehensive and helpful information about disks. In addition to displaying the information related to the amount of free space available on the mounted file systems, these commands can also obtain information about the amount of space occupied by each of the directories in each file system. Stay with us so that you can easily check free disk space in the Linux system.
Linux commands to check disk space
- df command: It stands for disk-free, which displays the free and usable space of the Linux file system.
- du command: provides information about the disk space occupied by the specified files and their subdirectories.
- btrfs fi df /device/ command: Provides details on how much space a btrfs-based file or mount point uses.
First method: Linux df command
One of the easiest ways to check free disk space in Linux is the Linux df command, which displays available and accessible disk space. The main syntax of the df command is as follows:
df [options] [devices]
Substitutions in brackets are optional. To check the Linux disk space, type the following command in the Linux command line:
The df command, without specifying any options, displays a list containing the names of all installed devices. Also, after entering the above command (df-H), the disk space will be displayed in human-readable format (MB and GB).
The output of df- H command:
Explanations about the output of the df command
You may not understand the output well, and some parts are confusing for you to review, so we will give a description in this field to guide you well.
Explanation of the specified parts in Output:
|Name shown||valid field name||explanation|
|Filesystem||Source||The Mount point source is often a disc device in Linux.|
|Available||Avail||Linux’s total number of available blocks.|
|Used||Used||the number of utilized blocks on a Linux drive.|
|1K-blocks||Size||Linux disc space in terms of the total number of blocks.|
|Mounted on||Target||mount point for Linux disk space.|
|Use%||Pcent||Used percentage divided by size.|
When checking disk space, the df command displays a list of “file systems” with their respective sizes, used space, and free space. The disk list contains the following categories for your actual disks:
So you can easily find actual disks among a wide range of disks.
The Linux system may have created different partitions on the disk for Boot, EFI, root, swap, and home. These partitions are indicated by a number at the end of the “disk name” such as /dev/sda1, /dev/nvme0n1p2, etc.
It is also possible to determine which partition is used for which purpose from the installation point.
tmpfs: The temporary file system or tmpfs is used to store files in virtual memory.
udev: This file system stores information about a USB, CD ROM, and network card when connected to your system.
/dev/loop: are loop-based tools. Because of Snap programs, you will see many of them when checking disk space in Ubuntu. Loops are virtual devices that block device access to regular files. Snap programs are boxed into their own virtual disk using loop devices. You don’t need to count their disk space consumption separately because they are under root.
Access to specific file system information through the df command
If you specify a device or mount point, df only displays information about files which stored physically on that device. For example, the following command displays data for the specified partition /dev/sda:
# Linux Check Disk Space for /dev/sda #
df –h /dev/sdc1
For example, the output of executing the /dev/sda command to check the amount of disk space consumption can be as follows:
Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda 2930266584 69405248 2859579472 3% /data
On Linux, you can also monitor nvme disk usage. For example, you can use the /dev/nvme0n1p2 partition:
df –h /dev/nvme0n1p2
When checking disk space on Linux, you can get a deeper look by sending the output format described by “valid field name” as below. Try the following command as an example:
df –output=source,used,avail /data/
Filesystem Used Avail /dev/md0 5.4G 115G udev 0 11M tmpfs 6.2M 414M tmpfs 4.1k 1.1G tmpfs 4.1k 5.3M tmpfs 0 1.1G /dev/md2 818G 688G tmpfs 0 210M tmpfs 0 210M /dev/mapper/cryptvg-mybackup 77G 526G
Access all fields to check disk space in Linux via the df command
If you need to get information about all available fields to check Linux disk space, enter the following command:
Filesystem Type Inodes Iused Ifree Iuse% 1K-blocks Used Avail Use% File Mounted on udev devtmpfs 379248 333 378915 1% 10240 0 10240 0% - /dev tmpfs tmpfs 381554 498 381056 1% 610488 9704 600784 2% - /run /dev/sdc1 ext3 956592 224532 732060 24% 14932444 7836056 6331204 56% - / tmpfs tmpfs 381554 1 381553 1% 1526216 0 1526216 0% - /dev/shm tmpfs tmpfs 381554 4 381550 1% 5120 0 5120 0% - /run/lock tmpfs tmpfs 381554 14 381540 1% 1526216 0 1526216 0% - /sys/fs/cgroup /dev/sda btrfs 0 0 0 - 2930266584 69405248 2859579472 3% - /data tmpfs tmpfs 381554 4 381550 1% 305244 0 305244 0% - /run/user/0
Get df output in a human-readable format
If you want the output of the df command to be readable by humans, be sure to add -h to the df command.
df -h ### Human format
You can also get information about Linux disk space size in gigabytes, megabytes, and terabytes.
df -m ### Show output size in one-megabyte df -k ### Show output size in one-kilobyte blocks (default)
Display disk space size in terms of inodes instead of blocks
All file-related data in a Linux file system is stored in a data structure called an inode. To view Linux disk space inode information, type:
df –i –h
Filesystem Inodes Iused Ifree Iuse% Mounted on udev 371K 333 371K 1% /dev tmpfs 373K 498 373K 1% /run /dev/sdc1 935K 220K 715K 24% / tmpfs 373K 1 373K 1% /dev/shm tmpfs 373K 4 373K 1% /run/lock tmpfs 373K 14 373K 1% /sys/fs/cgroup /dev/sda 0 0 0 - /data tmpfs 373K 4 373K 1% /run/user/0
View the type of file system displayed
Enter the following commands to see more details on the amount of disk usage and access to the type of file system and blocks such as ext4, btrfs, ext2, nfs4, fuse, cgroup, cputset, and others:
df –T –h
df –T –h /data/
The following output provides information about Linux disk space usage and file system type:
Filesystem Type Size Used Avail Use% Mounted on /dev/sda btrfs 2.8T 67G 2.7T 3% /data
Limiting a list to a specific type of file system
For this purpose, use the following syntax:
df –t ext3 #Only see ext3 file system
df –t ext4 #Only see ext4 file system
df –t btrfs #Only see btrfs file system
Removing the specified file system type
If you want to list all file systems except for a specific file system type when checking the disk space, you should enter the following command:
df –x TYPE
For example, to list all file systems except ext2, enter the following command:
On Ubuntu Linux, when checking disk space used by snap packages, squashfs filesystem spam can be hidden by doing the following:
df –x squashfs
Checking the Linux disk space usage report
To check the report of all file systems and disk spaces, run the following commands:
Getting more help on the df command
For detailed instructions on how to check disk space in Linux using the command, run the –help parameter:
You can also read its man page by entering the following command:
Checking the installation of all partitions and disks
The df command only displays free disk space for mounted file systems. If you are running multiple Linux distributions on a single hard disk or your system is equipped with multiple disks, you need to mount them first to see the free space on the disk or partition.
Use the lsblk command to access information about all system partitions and disks.
You can mount a disk partition once you know its name via the following command:
sudo mount /dev/sdb2 /mnt
Method 2: Linux du command
The du command is handy for tracking disk space hogs and knowing the names of files that take up the most disk space. As a result, by entering the du command, the user will see the consumption of files, folders, etc., in kilobytes.
The syntax of this command is as follows:
du [options] [directories and/or files]
The following command is used to access information about the name and space consumption of each directory (all sub-branches in the directory tree):
16 ./.aptitude 8 ./.ssh 45 ./apcupsd 12 ./.squidview 8 ./kernel.build 12 ./.elinks 12 ./.vim 8 ./.config/htop 12 ./.config 648 .
In the above output, the first column displays the file size (in kilobytes), and the second column indicates the name of the directory or file.
Access disk usage information in human-readable format by the du command
If you want to get information in a human-readable format to check disk space usage in K (kilobytes), M (megabytes), and G (gigabytes) for all directories and subdirectories, enter the following command :
Access information about any file or directory tree with the du command
The following command is used to check the space consumption of the /etc/ directory:
sudo du /etc/
sudo du -h /etc/
To get a report on the size of the files under hdparm, iptunnel, and ifconfig in the /sbin folder, you can run the following command:
du /sbin/hdparm /sbin/iptunnel /sbin/ifconfig
du -h /sbin/hdparm /sbin/iptunnel /sbin/ifconfig
228K /sbin/hdparm 32K /sbin/iptunnel 112K /sbin/ifconfig
Find out how much disk space is used by a particular directory via the du command
If we want to know the total disk space occupied by a specific file or directory, regardless of subdirectories, we must add the -s option to the du command:
sudo du -s /etc/
sudo du -sh /etc/
View all files in disk space check by du command
To view all files, not just directories, in disk space usage, it is necessary to add the -a(all) option to the du command:
du -a /etc/
du -a -h /etc/
8.0K /etc/w3m/config 4.0K /etc/w3m/mailcap 12K /etc/w3m 12.0K /etc/ConsoleKit/run-seat.d 8.0K /etc/ConsoleKit/seats.d/00-primary.seat 8.0K /etc/ConsoleKit/seats.d 4.0K /etc/ConsoleKit/run-session.d 20K /etc/ConsoleKit ... .... .. ... 12.0K /etc/ssh/ssh_host_rsa_key 4.0K /etc/ssh/ssh_host_rsa_key.pub 8.0K /etc/ssh/ssh_host_dsa_key 244K /etc/ssh/moduli 4.0K /etc/ssh/sshd_config 272K /etc/ssh 8.0K /etc/python/debian_config 12.0K /etc/python 0 /etc/.pwd.lock 4.0K /etc/ldap/ldap.conf 8.0K /etc/ldap 5.3M /etc/
Note: The asterisk (*) can be used to replace any character. For example, you can enter the following command to list the sizes of png files in the current directory:
du -ch *.png
78K CIQTK4FUAAAbjDw.png-large.png 53K CX23RezWEAA0QY8.png-large.png 328K CY32cShWkAAaNLD.png-large.png 12K CYaQ3JqU0AA-amA.png-large.png 228K CYywxDfU0AAP2py.png 172K CZBoXO1UsAAw3zR.png-large.png 384K Screen Shot 2016-01-19 at 5.49.21 PM.png 324K TkamEew.png 4.0K VQx6mbH.png 64K fH7rtXE.png 73K ipv6-20-1-640x377.png 392K unrseYB.png 1.8M total
Note: When the -c option is added to the du command, du returns the final result.
If you want to get information about the top directories that take up disk space in /etc/, try the following command:
du -a /etc/ | sort -n -r | head -n 10
To get more information and help about the du command, type the following command:
You can also use the following commands to get help:
man du man df man btrfs
Method 3: Use btrfs fi df command
Using the btrfs fi df command is used to view the disk space usage information of the btrfs file system at the mount point. The syntax of the command is as follows:
btrfs filesystem df /path/ btrfs fi df /dev/path btrfs fi df [options] /path/
sudo btrfs fi df /data/ sudo btrfs fi df -h /data/
Data, RAID1: total=56.00GiB, used=63.40GiB System, RAID1: total=4.00MiB, used=26.00KiB Metadata, RAID1: total=8.00GiB, used=3.29GiB GlobalReserve, single: total=512.00MiB, used=0.00B
To access the raw numbers in bytes, enter the following command:
sudo btrfs fi df -b /data/
sudo btrfs fi df -k /data/ ### show sizes in KiB ## sudo btrfs fi df -m /data/ ### show sizes in MiB ## sudo btrfs fi df -g /data/ ### show sizes in GiB ## sudo btrfs fi df -t /data/ ### show sizes in TiB ##
Method 4: Linux commands ls -al, stat, fdisk -l, dust to check free disk space
The du and df commands are among the most common and widely used commands to check free disk space, but they may not be enough to get some information so you can try some other methods instead of the du and df commands:
ls -al Linux command
Displays the entire contents of a specific directory along with its size.
Linux stat command
To obtain any statistical information and the size of a file system or a directory, the following command must be executed:
Linux fdisk -l command
Displays information about disk partitioning and disk size:
Linux dust command
It is a popular alternative to the du command written in Rust, which can be found in the official Arch Linux repository you already know. You can find it in the GitHub Releases section and packages for other Linux distributions.
Method 5: Checking free disk space graphically
In Linux distributions, especially Ubuntu, you can easily check the free and occupied disk space by installing the Disk Usage Analyzer tool and accessing all disks and partitions, as well as the disk space occupied by installed partitions. Also, you can get the details about them and even install them by clicking on some partitions. Fleshlight is recommended for the KDE desktop environment.
Both programs display disk usage as a series of concentric rings, with the inner ring representing the root directory (main/home, but you can change that) and the outer rings representing each successive directory. When you move the cursor over a section, you will see more details about its content.
In addition, the GNOME Disks utility is another powerful and valuable tool in the field of checking disk space. After installing this tool, select the desired disk and a partition to view the available space on the drive. If you haven’t installed the partition before, click the “play” button to install the partition.
If you want to access the information obtained by entering the df command and the various options of this command about checking free disk space through a utility in a graphical view, the gnome-disk-utility for the GNOME desktop environment can respond to your needs. By installing and running this tool, you can see the disks detected by your system, and it will display the used space and free space and all the details of the partitions with a click on each partition.
Most of the built-in Linux tools for checking file space are the ones mentioned above. You can also use software such as Disks (GUI), Ncdu, etc. that perform the same function.
The df, i.e., disk free command, can be used to display the amount of available storage on all mounted drives.
Delete files that are not needed and take up a lot of disk space..
Remove packages that are not necessary for use
Delete additional and unnecessary programs
Deleting unnecessary system logs
If you are using Ubuntu, you can remove apt-cache.
Choose Manage from the shortcut menu when you right-click Computer.
Click Storage twice.
Click Disk Management twice.
Right-click the partition in the list, then choose Extend Volume.
Resize the partition as directed, then click Finish.
Finally, close the computer management window when finished.
Users need information about occupied and free disk space for various reasons. Therefore, according to the training we gave, the du command is used to check the space consumed by files, and the df command is used more to access a report about the disk space usage of the Linux file system. If you use the btrfs file system and need to estimate their disk space usage, use the btrfs df command.
There are many different ways to check free disk space in Linux, and we mentioned the most common and simple ones in this tutorial. We tried not to limit ourselves to one method but to use different methods and various options so that you can get more and more accurate information about Linux disk space and manage your system better.
Administrators of Linux servers can also purchase a suitable Linux VPS plan to meet their needs in terms of resources and disk space for optimal server performance and then to better manage the resources using the commands we taught and get information about the disk space.
We hope that our training has guided you well in this field. If you have experience using other tools in the graphic space and we have not mentioned them, share them with users and us in the comments section; also, if you have any questions related to the topic of the article, ask us, and we will guide you as soon as possible.