How to Get Total Storage in Linux using df command

Posted on

Introduction

This article is an article containing information about how to get storage size in Linux operating system. There are several ways for getting information about the storage size of a server in Linux operating system. Precisely, in this article, the discussion is only focusing on using one command. It is a command available in Linux operating system in general. That command is the ‘df’ command. According to its manual page, the command itself will give a report of file system disk space usage. The command itself is normally available as part of the default command in Linux operating system.

Using ‘df’ command to display the total storage

The following is an example of the command execution of ‘df’ command :

user@hostname:~$ df
Filesystem     1K-blocks      Used Available Use% Mounted on
udev             8058368         0   8058368   0% /dev
tmpfs            1618208      4200   1614008   1% /run
/dev/sdb5      471359832 378287640  69105424  85% /
...
user@hostname:~$

The output of the above command execution is the usage of the storage available in the operating system. In the output, the usage is in percentage format. The main purpose for using the ‘df’ command in this article is to be able to see the total usage in the operating system.By modifying the command, the following is the sequence of the command modification. First of all, try to display the total usage in human readable format. Add the –h parameter as follows :

$ df -h

The following is the output of the above command execution :

user@hostname:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            7.7G     0  7.7G   0% /dev
tmpfs           1.6G  4.1M  1.6G   1% /run
/dev/sdb5       450G  362G   66G  85% /
...
user@hostname:~$ 

There is a slight difference on the output above. The output is already in a certain metric size. It is in a human readable format using Gigabyte metric size. Following the modification of the above command to just focus on the size, the following is another command :

df -h --output=size

The output of the above command execution exist as follows :

user@hostname:~$ df -h --output=size
 Size
 7.7G
 1.6G
 450G
 ...
user@hostname:~$ 

Finally, the output is change into another format. It only display the size using the additional –output=size parameter. Finally, to be able to count all of the size of the available aspect of the storage, the following is another modification of the command :

$ df -h --output=size --total
user@hostname:~$ df -h --output=size --total
 Size
 7.7G
 1.6G
 450G
 ...
 484G
user@hostname:~$ 

Again, the output is changing. There is an additional line in the end giving the sum of all the sizes available in the previous row. Finally, in order to display on the last line of the output where it is indicating the grand total of all the size of the items, the following is the command modification :

$ df -h --output=size --total | awk 'END {print $1}'
user@hostname:~$ df -h --output=size --total | awk 'END {print $1}'
484G
user@hostname:~$ 

Leave a Reply