A quick guide to checking disk space on Linux

In the Linux world | Unix system administration One of our tasks is to perform disk space check in Linux. Performing a check disk space operation on Linux allows us to know about the current use of the mount point on the system. Here is a list of Linux commands for checking disk space.

Linux disk space check commands

1. The df command.

df is the main native command built inside Linux system used to check disk space on Linux. df stands for “free disk”. This means it displays the use of mount points in Linux. There are various options available for the df command. Without any options, it displays information like file system, used space, how much free space, and usage as a percentage, as shown below:

[[email protected] ~]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_destroyer-lv_root
                      16070076   8763548   6490196  58% /
tmpfs                  1960684        36   1960648   1% /dev/shm
/dev/sda1               495844     37181    433063   8% /boot
/dev/mapper/vg_andreyex-lv_andreyex
                        198337      5647    182450   4% /andreyex
/dev/sde1              1233308      3356   1167304   1% /home
[[email protected] ~]#

There are various options within the df command, so let’s explore one by one.

and. Human readable format

The example output without any option displays the usage in bytes. In order to make it more informative, use the option “ -h “Along with the df command which will display usage in Gb. Mb as shown below:

[[email protected] ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_destroyer-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_andreyex-lv_andreyex
                      194M  5.6M  179M   4% /andreyex
/dev/sde1             1.2G  3.3M  1.2G   1% /home
[[email protected] ~]#

b. Specific mount point

In “1a” the system displays information related to all mount points on the system. What if you want information related to a specific mount point. Then you must specify a mount point after the df command, which will print information about a specific mount point and only, for example, to display information related to / home, use the command point:

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

from. Filesystem type

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

	
[[email protected] ~]# df -hT
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/mapper/vg_destroyer-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_andreyex-lv_andreyex
              ext4    194M  5.6M  179M   4% /andreyex
/dev/sde1     ext4    1.2G  3.3M  1.2G   1% /home
[[email protected] ~]#

e. Limiting the list according to the type of file system

  • Including a certain type of file system.

In case you only want to (enable) the ext4 file system on the screen. Use “-t” followed by “filesystem type” as shown below:

[[email protected] ~]# df -hTt ext4
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_destroyer-lv_root
ext4 16G 8.4G 6.2G 58% /
/dev/sda1 ext4 485M 37M 423M 8% /boot
/dev/mapper/vg_andreyex-lv_andreyex
ext4 194M 5.6M 179M 4% /andreyex
/dev/sde1 ext4 1.2G 3.3M 1.2G 1% /home
[[email protected] ~]#

  • Except for a certain type of file system type

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

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

In the output above, all ext4 file systems are excluded and only information for the “tmpfs” file system type is displayed.

e. Inode information.

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

[[email protected] ~]# df -hi
Filesystem            Inodes   IUsed   IFree IUse% Mounted on
/dev/mapper/vg_destroyer-lv_root
                        999K     90K    909K    9% /
tmpfs                   479K       4    479K    1% /dev/shm
/dev/sda1               126K      39    125K    1% /boot
/dev/mapper/vg_andreyex-lv_andreyex
                         50K      12     50K    1% /andreyex
/dev/sde1                77K     294     77K    1% /home
[[email protected] ~]#

e. All file systems

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

[[email protected] ~]# df -ha
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_destroyer-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_andreyex-lv_andreyex
                      194M  5.6M  179M   4% /andreyex
/dev/sde1             1.2G  3.3M  1.2G   1% /home
gvfs-fuse-daemon         0     0     0   -  /root/.gvfs
[[email protected] ~]#

2. The du command

The “du” command also shows the use of files or directories in Linux. du stands for “disk space usage”.

The basic command syntax is as follows:

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

and. Readable

In order to display an image in a readable format, i.e. in terms of GB or MB, instead of the Kb variant, use “-h”.

[[email protected] 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    .
[[email protected] tmp]#

b. Specific file or directory

To display information related to any file or directory, use the du command as shown below:

For example, to use the tmp directory, use the command below.

[[email protected] 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
[[email protected] tmp]#

from. Simplify the output. You saw in output 2B that all files or directories were shown. However, if you do not want to show all directories, and instead you just want information related to that directory, then use with the “-c” option.

[[email protected] ~]# du -sh /tmp
492K    /tmp
[[email protected] ~]#

Please check the guidelines for extending the connection point if the usage threshold is reached.

Sidebar