X
    Categories: Linux

Quick guide for Linux check disk space


In the world of Linux | Unix system administration one of our tasks is to perform Linux check disk space. Performing Linux check disk space operation makes us aware about the current utilisation of the mount point within the system.


Here is list of command for Linux check disk space.                                               

Linux check disk space commands                          

1.  df command.

df is the major native command built inside the linux system used for linux check disk space. df stands for “disk free”. Meaning that, it displays utilization of the mount points in linux. There are various options available for df command. Without any option it displays information like file system , used space , how much space available and also the utilization in terms of percentages as below:

[root@rhel1 ~]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_rhel1-lv_root
                      16070076   8763548   6490196  58% /
tmpfs                  1960684        36   1960648   1% /dev/shm
/dev/sda1               495844     37181    433063   8% /boot
/dev/mapper/vg_uxtechno-lv_uxtechno
                        198337      5647    182450   4% /uxtechno
/dev/sde1              1233308      3356   1167304   1% /home
[root@rhel1 ~]#

There are different options within df commands, lets explore one by one.

a. Human readable format

In the sample output without any option displays the utilization in bytes. To make it more informatory use option “-h” along with df command which will display the utilization is Gb. Mb as below:

[root@rhel1 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_rhel1-lv_root
                       16G  8.4G  6.2G  58% /
tmpfs                 1.9G   36K  1.9G   1% /dev/shm
/dev/sda1             485M   37M  423M   8% /boot
/dev/mapper/vg_uxtechno-lv_uxtechno
                      194M  5.6M  179M   4% /uxtechno
/dev/sde1             1.2G  3.3M  1.2G   1% /home
[root@rhel1 ~]#

b. Specific mount-point

In “1a” system displays information related to all the mount points within the system. What if you want information related to any specific mount point. Then you must give the mount point after the df command which will print information related that mount point only. eg. to display information related to /home mount point use below command:

[root@rhel1 ~]# df -h /home
Filesystem            Size  Used Avail Use% Mounted on
/dev/sde1             1.2G  3.3M  1.2G   1% /home
[root@rhel1 ~]#

c. File system type

Let’s say you also need information related to filesystem type (ext2, ext3 or ext4) in the output. Then use option “-T” along with df command.

[root@rhel1 ~]# df -hT
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/mapper/vg_rhel1-lv_root
              ext4     16G  8.4G  6.2G  58% /
tmpfs        tmpfs    1.9G   36K  1.9G   1% /dev/shm
/dev/sda1     ext4    485M   37M  423M   8% /boot
/dev/mapper/vg_uxtechno-lv_uxtechno
              ext4    194M  5.6M  179M   4% /uxtechno
/dev/sde1     ext4    1.2G  3.3M  1.2G   1% /home
[root@rhel1 ~]#

d. Limiting the list as per the filesystem type

  • Including certain type of file system type.

In case you only want to (include) display filesystem of the type ext4. Then use “-t” option followed by “Filesystem type” as below:

[root@rhel1 ~]# df -hTt ext4
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_rhel1-lv_root
 ext4 16G 8.4G 6.2G 58% /
/dev/sda1 ext4 485M 37M 423M 8% /boot
/dev/mapper/vg_uxtechno-lv_uxtechno
 ext4 194M 5.6M 179M 4% /uxtechno
/dev/sde1 ext4 1.2G 3.3M 1.2G 1% /home
[root@rhel1 ~]#
  • Excluding certain type of filesystem type

Let’s say, you don’t want filesystem type ext4 to be appeared in the output then you must use “-x” followed by type of filesystem.

[root@rhel1 ~]# df -hTx ext4
Filesystem    Type    Size  Used Avail Use% Mounted on
tmpfs        tmpfs    1.9G   36K  1.9G   1% /dev/shm
[root@rhel1 ~]#

The above output excluded all the filesystem with ext4 and only displayed information for the “tmpfs” type of filesystem.

e. inode information. 

If you want to print information related to inodes then use option “-i” along with the df command.

[root@rhel1 ~]# df -hi
Filesystem            Inodes   IUsed   IFree IUse% Mounted on
/dev/mapper/vg_rhel1-lv_root
                        999K     90K    909K    9% /
tmpfs                   479K       4    479K    1% /dev/shm
/dev/sda1               126K      39    125K    1% /boot
/dev/mapper/vg_uxtechno-lv_uxtechno
                         50K      12     50K    1% /uxtechno
/dev/sde1                77K     294     77K    1% /home
[root@rhel1 ~]#

f. All filesystem 

In case you want to print information related to all file system which includes dummy filesystem also. Then “-a” option after df command as below:

[root@rhel1 ~]# df -ha
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_rhel1-lv_root
                       16G  8.4G  6.2G  58% /
proc                     0     0     0   -  /proc
sysfs                    0     0     0   -  /sys
devpts                   0     0     0   -  /dev/pts
tmpfs                 1.9G   36K  1.9G   1% /dev/shm
/dev/sda1             485M   37M  423M   8% /boot
none                     0     0     0   -  /proc/sys/fs/binfmt_misc
sunrpc                   0     0     0   -  /var/lib/nfs/rpc_pipefs
/dev/mapper/vg_uxtechno-lv_uxtechno
                      194M  5.6M  179M   4% /uxtechno
/dev/sde1             1.2G  3.3M  1.2G   1% /home
gvfs-fuse-daemon         0     0     0   -  /root/.gvfs
[root@rhel1 ~]#

2. du command

“du” command also displays utilization related to file or directory in linux. du stands for “disk usage”.

Basic syntax of du command:

du [options] [<file location> or <dir location>]

a. Human readable 

To display output in human readable format ie in terms of Gb or Mb instead of Kb use “-h” option.

[root@rhel1 tmp]# du -h
148K    ./orbit-user1
4.0K    ./ssh-LFeSg17790
4.0K    ./mann
4.0K    ./mannu
4.0K    ./.esd-0
4.0K    ./ssh-PYFhE19514
4.0K    ./pulse-BIXXUmlVMfbC
4.0K    ./.esd-513
4.0K    ./.X11-unix
4.0K    ./.ICE-unix
4.0K    ./keyring-qO7Ako
4.0K    ./pulse-WR3BqwGvaoeJ
84K     ./orbit-user2
4.0K    ./.esd-514
4.0K    ./keyring-N0Gi7c
4.0K    ./pulse-0lGpGWbHcush
12K     ./orbit-root
492K    .
[root@rhel1 tmp]#

b. Specific file or directory 

To display information specific to any directory  or file,  use that file or dir followed by du command as below:

E.g. for tmp dir  use below command.

[root@rhel1 tmp]# du -h /tmp
148K /tmp/orbit-user1
4.0K /tmp/ssh-LFeSg17790
4.0K /tmp/mann
4.0K /tmp/mannu
4.0K /tmp/.esd-0
4.0K /tmp/ssh-PYFhE19514
4.0K /tmp/pulse-BIXXUmlVMfbC
4.0K /tmp/.esd-513
4.0K /tmp/.X11-unix
4.0K /tmp/.ICE-unix
4.0K /tmp/keyring-qO7Ako
4.0K /tmp/pulse-WR3BqwGvaoeJ
84K /tmp/orbit-user2
4.0K /tmp/.esd-514
4.0K /tmp/keyring-N0Gi7c
4.0K /tmp/pulse-0lGpGWbHcush
12K /tmp/orbit-root
492K /tmp
[root@rhel1 tmp]#

c. Summarise output. 

In the output 2b you have seen that, all the files or directories utilization have been shown. However, if you don’t want to show this all directories instead you just want information related to that directory only in the output then use “-s” option.

[root@rhel1 ~]# du -sh /tmp
492K    /tmp
[root@rhel1 ~]#

Please check guide on extending mount point in case your utilization reached threshold.

View Comments (0)

Related Post