How to Check Disk Space in Linux from the Command Line

Disk space monitoring is considered a very important task when working with any device, whether it is a mobile phone, laptop, desktop, or even a tablet. It is important to ensure the proper functioning of any device by keeping an eye on the disk space. This helps you in identifying the programs or the applications that are using a large amount of space and informs you if you are about to run out of disk space.

Like every other operating system, Linux also provides multiple ways to keep track of the disk space on your device, including both CLI-based and GUI-based methods. In Linux, however, most operations are performed via the command line. Therefore, Linux users are more likely to be interested in methods of checking disk space via the command line. This is why our discussion today will revolve solely around methods for checking disk space in Linux from the command line.

Note: All the methods shown below have been tested in Linux Mint 20.

Checking the Disk Space in Linux from the Command Line

There are multiple ways to check the disk space in Linux; however, the most effective ones involving the command line interface have been presented below.

Method 1: Using the df Command

The df command stands for Disk Filesystem, and it is a built-in utility in the different flavors of the Linux operating system. The df command is used to monitor disk space utilization, as well as the total available space. To check the disk space using this utility, proceed as follows:

First, launch the terminal in Linux Mint 20 by clicking on its desktop icon, shown in the image below:

After launching the terminal in Linux Mint 20, execute the following command in the terminal:

$ df

Running this command will display the total space of the whole file system, the total amount of used space, as well as the available space, along with some other information, as shown in the following image:

Method 2: Using the df command with the -a Flag

The df command can also be used in conjunction with the -a flag, which is used to display the disk space of all the file systems (i.e., your actual file system and also the dummy ones). Perform the steps shown below to use the df command with the -a flag:

Launch the terminal in Linux Mint 20 and execute the command shown below:

$ df –a

The output of this command will be quite large, and you will have to scroll through your terminal to view the entire output. This is because the -a flag does not only print the disk space of a single file system; rather, it does so for all available file systems.

Method 3: Using the df command with the -h Flag:

Certain technical terms may not be easily understandable by a new user. For example, in the outputs of both the methods discussed above, you can see a column named “1K-blocks.” This column represents the total number of “1K-blocks” present in each file system. In other words, this is the size of the file system in bytes, which can be difficult to interpret and memorize. Basically, it is a technical way of representing the size of each file system, but this is not so intuitive for a layman. Therefore, the -h flag can be used with the df command to display the disk space in a more human-readable format. To make this happen, follow the steps provided below:

Launch the Linux Mint 20 terminal as explained above, and then execute the following command:

$ df –h

Running this command will display the disk space of your file system in a way that you will easily be able to interpret, i.e., the disk space will be displayed in megabytes (MBs), gigabytes (GBs), etc. You can see this output in the image below:

In the same manner, you can also use the -k and -m flags with the df command to check the disk space in Linux via the command line in kilobytes and megabytes, respectively. This can be done if you require the disk space in a specific unit for a specific purpose. By allowing this, the df command or utility provides you with the flexibility to check your disk space in whichever format you prefer.

Conclusion

This article showed you how to check the available disk space in a device using the command-line in Linux. All the three methods described above were a variation of the df command. You can easily use the df command to check the disk space in Linux from the command line by adjusting the flags according to your requirements. Or, you can simply use this command alone and without any flags. The output of this command will help you to see your current disk space usage and the amount of free space.

Apart from the use cases of the df command discussed in this article, this command can also be used to check the disk space of a specific file system; to know the total, available, and used inodes of a file system; to check the type of each file system; to filter out the file systems based on a particular type; and much more. However, all of these use cases are beyond the scope of this article. That is why we have only focused on the use cases of the df command that are directed towards checking the disk space.



from Linux Hint https://ift.tt/37ksjUa

Post a Comment

0 Comments