Linux Check Disk Space
It is an essential step to manage disk space over a Linux server. For example, various applications of package manager inform us how much disk space would be needed for the installation process. We should understand how much space our system has available for the data to be meaningful.
In this topic, we will understand how to apply the df command for checking the disk space on Linux and also the du command for displaying the disk space usage of the file system.
Check disk space with the df command
Using the df command, we can check our disk space by opening the terminal window and simply typing the following command:
This command is short for disk free. It shows us the space amount taken up by distinct drives. The df command by default shows values in the 1-kilobyte blocks.
Check Disk Space in Gigabytes and Megabytes
We can show the usage of the disk in human-readable format by including the following option with the df command:
After using the above command, the size will display in gigabytes, megabytes, and kilobytes.
Knowing the Format of the Output
The df command will list various columns which are listed and explained below:
The filesystems list contains our virtual hard drives and physical hard drivers as well:
For example, the tmpfs/run/lock directory is used for creating lock files. The lock files are the files that restrict more than one user from modifying a similar file at a time.
Display a Particular File System
The df command could be used for displaying a particular file system:
Also, we can add a backslash:
It will show the usage on our main hard drive. We can apply the mount point (inside the Mounted on entry) for specifying the drive we wish to check.
Note: The df command targets a complete filesystem only. Even when we describe a single directory, the df command will know the space of the entire drive.
Display the File Systems by Their Type
We can use the following command for listing every file system by its type:
It will list the drives along with the type, i.e., ext4 in a more human-readable style.
Show Size in 1000 Rather Than 1024
We can show the usage of the disk in 1000 units rather than 1024:
It can address the confusion point inside the storage mechanism. Many manufacturers of hard drives sell their hard drives in distinct sizes based on the 1000 bytes which are equal to 1 kilobyte.
Although, operating systems categorize that space up, where:
1 kilobyte = 1024 bytes
The hard drive of 1000 gigabytes ends up with 930 gigabytes of accessible storage roughly due to this reason.
Check Disk Space Using the du Command
In Linux, the du command can also be used for displaying the usage of the disk. This tool can show the usage of the disk for a single directory in Linux, providing us a finer-grained perspective of our disk usage. We can use it for displaying the space amount utilized by our current directory:
We can enable the du command to be more human-readable just like the df command:
It will show how much disk space is consumed by the contents of our current directory and the list of various contents of the current directory.
We can also clarify the display by using the -s option:
It will show how much space is consumed by our current directory.