df - disk space

df command examples and explanation

Df command is used to list all the file systems along with the sizes.

Let’s talk about a situation,

We are working as Linux administrator and all of a sudden we have received a notification mail/alert saying that, disk space is getting low on one of the server.

 

To figure out the exact problem, we log into the machine and want to know,

  • Which file system storage is going down?  - df command.
  •  Which file on that directories are taking lot of space? - du command.

 

In this section we focus more on df command and its use cases.


df command syntax:

df options directory-name

 

Example:

Understanding the storage utilizations of the file systems:

By using the command "df –k" we can list the file systems in 1k blocks usage.

Here, as we are not giving any particular file system, it is showing for entire mounted devices.

[root@sys1 ~]# df -k
Filesystem                1K-blocks Used     Available   Use%  Mounted on
/dev/sda2                 15118728  3452112  10898616    25%   /
tmpfs                     953888    76       953812      1%    /dev/shm
/dev/sda1                 3023760   96992    2773168     4%    /boot
/dev/sda3                 5164392   3777284  1124772     78%   /repo
/dev/mapper/ithvg-ithlv   297485    10254    271871      4%    /ith
/dev/mapper/ithvg1-ithlv1 198562    5646     182888      3%    /mysql
/dev/sr0                  3632776  3632776     0       100%   /media/
RHEL_6.4
x86_64 Disc1

 

Understanding the storage utilizations in human readable format:

Things are little difficult with 1k blocks, so let’s use df -h option for better understanding output.

[root@sys1 ~]# df -h
Filesystem                Size    Used  Avail  Use%   Mounted on
/dev/sda2                 15G     3.3G  11G    25%     /
tmpfs                     932M    76K   932M   1%      /dev/shm
/dev/sda1                 2.9G    95M   2.7G   4%      /boot
/dev/sda3                 5.0G    3.7G  1.1G   78%     /repo
/dev/mapper/ithvg-ithlv   291M    11M   266M   4%      /ith
/dev/mapper/ithvg1-ithlv1 194M    5.6M  179M   3%      /mysql
/dev/sr0                  3.5G    3.5G   0     100%    /media/RHEL_6.4
                                                                                                               
x86_64 Disc 1

 

From the above output, we can see the storage sizes are presented in human-convenient format. Like Megabytes, GigaBytes etc.

 

List the file system utilization available for a directory:

[root@linbox1 etc]# df -h /var
Filesystem      Size   Used   Avail  Use%   Mounted on
/dev/sda2       25G    4.6G   20G    19%      /

 

/var directory is mounted on /dev/sda2 filesystem and this filesystem still have lot of available space (20G) for usage.

Of course, this 20G is included for all of the directories running under “/” root directory. /Var is just a part of it.

 

What if,we want to know the total size of /var directory on the filesystem?

 

List all file systems including dummy file systems:

BY using the command #df –a will display all the file systems including the dummy file systems also.

Dummy file systems means the file systems that exist in the machine but they are not used by the machines.

[root@sys1 ~]# df -a
Filesystem               1K-blocks  Used      Available Use%  Mounted on
/dev/sda2                 15118728  3452112   10898616  25%   /
proc                        0         0         0        -    /proc
sysfs                       0         0         0        -    /sys
devpts                      0         0         0        -    /dev/pts
tmpfs                     953888      76       953812    1%   /dev/shm
/dev/sda1                 3023760     96992    2773168   4%   /boot
/dev/sda3                 5164392     3777284  1124772   78%  /repo
/dev/mapper/ithvg-ithlv   297485      10254    271871    4%   /ith
/dev/mapper/ithvg1-ithlv1 198562      5646     182888    3%   /mysql
none                        0         0          0       -    /proc/sys/fs
                                                                                                                        /binfmt_misc
vmware-vmblock              0         0          0       -    /var/run/vm
                                                                                                                        block-fuse
sunrpc                      0         0          0       -    /var/lib/nfs/rp
                                                                                                                        c_pipefs
nfsd                        0         0          0       -    /proc/fs/nfsd
gvfs-fuse-daemon            0         0          0       -    /root/.gvfs
/dev/sr0                 3632776      3632776    0       100% /media/                                                                                                                                      
RHEL_6.4x                                                                                                               86_64Disc 1

 

In the above output the highlighted file systems are called the dummy file systems.

The disk space with inode information.

[root@sys1 ~]# df -i
Filesystem                Inodes   IUsed   IFree  IUse%  Mounted on
/dev/sda2                 960992   112288  848704  12%   /
tmpfs                     238472     4     238468  1%    /dev/shm
/dev/sda1                 192000    39     191961  1%    /boot
/dev/sda3                 328000    3900   324100  2%    /repo
/dev/mapper/ithvg-ithlv   76912      11    76901   1%    /ith
/dev/mapper/ithvg1-ithlv1 49400      11    49389   1%    /mysql
/dev/sr0                    0        0       0     -     /media/RHEL_6.4
                                                                                                                 
x86_64 Disc 1

Topics Summary