How to Check Disk Space in Linux
One important task for any Linux administrator is keeping track of and managing disk usage and how much free space each volume has. You’ll need to know how to check disk space in Linux.
One of the most important tasks in managing any Linux system is keeping tabs on disk space utilization. How much disk space are you using and how much do you have left?
Whether it’s a Linux desktop or a server, it’s crucial that you periodically check how much free space your hard drive or drives have left. Linux has a few tools for this job, so let’s look at how to check disk space on a Linux device.
Checking Disk Space on Linux Using Terminal Commands
Overseeing disk space usage in most operating systems is simple, with just one tool to rule them all. Things aren’t so cut and dry in Linux, as there are four different terminal commands to guide and assist with this requirement. That’s not counting ls, which is more commonly used to list files and directories but also provides the sizes of those objects.
The Linux df Command
The first tool we’ll look at is df, which stands for “disk-free”. If you want a fast, accurate review of disk utilization in Linux, this command is an important part of that task. Its output can be as simple or comprehensive as you want.
df -h
The simplest execution, the command above will show the disk space available in each mounted volume in an easy, human-readable format. Rather than displaying all sizes in 1K blocks, -h instructs the command to use the largest possible unit, such as G for gigabytes, M for megabytes, or K for kilobytes.
The second column shows the total size of the volume. Next, you see how much of that space each volume uses. The third and fourth columns show available space and the percentage used. Finally, the sixth column shows the mount point for each volume.
A more comprehensive view is available with the -a parameter. Called this way, df will also include pseudo, duplicate, and inaccessible file systems. Adding -T to the command will provide you with the type of filesystem each volume uses (e.g., ifs, ext2, ext3, etc.)
Finally, filesystems that have thousands upon thousands of very small files can have plenty of available space, but still run out of inodes to use. An inode is a data structure that describes a filesystem object such as a file or directory. It stores the attributes and disk block locations of that object’s data.
This is especially important to track on mail servers since they can often house millions of small files. You can ask df to show used and free inodes with the -i flag.
df -i
Checking Disk Usage in Linux with du
Another command provided within Linux is du. This is similar to df, except that it focuses on disk usage in the location being executed. Its basic output is much simpler, too.
du -h
As you can see, du -h shows, in human-readable format, how much disk space each directory and subdirectory uses from the present working directory. If you want to check the disk usage for a different directory, you can either cd to that directory or specify it at the end of the command.
du -h /home/jeff/documents/
Getting Detailed Information About a Volume, Directory, or File
Using the stat command in Linux, you can obtain all available information about a particular file or directory. This includes its size, how many blocks it consumes, and inode details. The output also shows ownership, what device the file or directory is stored on, and more.
Finally, Linux’s fdisk command can provide useful information for system administrators. By issuing the fdisk -l command, you’ll get disk size and partitioning information for your system. Note that this command must be executed as root, preferably using sudo.
How to Check Disk Space in Linux Using GUI Apps
Most Linux graphical desktop environments do provide utilities that offer some of the same functionality as the command line tools above. In Gnome, for example, the Disks application can provide much of the information you may need.
As you can see, Disks provides you with the size of the volume, free space remaining, and the percentage of disk space used. It also shows the device name for the volume, the filesystem used, and other details.
Gnome also has a graphical tool called Disk Usage. The KDE Plasma desktop has a similar application called Filelight. Both do the same basic thing: provide you with a graph showing your disk usage. The larger the concentric circle, the more space the particular file or directory uses. These tools are excellent for obtaining a high-level overview of how your volumes’ space is utilized.
Finally, while it may not be installed by default, GParted is a great Gnome alternative to fdisk for those who prefer to do things via the GUI. GParted shows you the partitioning scheme of all of your drives. It also allows you to create, reorganize, resize, and delete partitions.
You can install the application by opening Ubuntu Software and searching for GParted. If you’re using a different Linux distribution, GParted should be available through your distribution’s software repository of choice. It’s also available for the KDE Plasma desktop, but you may prefer the KDE Partition Manager if you’re using that GUI environment.
Learn How to Check Disk Space in Linux and Other Administration Tasks
If you’re new to running Linux, there’s a lot to learn. Fortunately, there are also many resources for doing that. We are just one such tool. Others include the Linux man-pages project, which provides a way to view manual pages online for many Linux commands and conventions.
You should also familiarize yourself with creating and listing users in Linux as well as creating and using groups. You’ll also find Linux to have very powerful tools for searching and acting on files.