AskWael

Menu

Linux Disk Space Usage Tracking

Language
Linux Disk Space Usage Tracking

Disk Space in Linux is full? Need help, so you can find and track what is using the disk space? In this article, we will explain how to do this.

There are two main ways to check disk space on Linux:

  • df command: View the amount of disk space used, and available on Linux Systems. Therefore this command is more of an overview.
  • du command: View the amount of disk space used by specific files, and for each sub directory. Therefore this command digs more into the details.

Linux check disk space with df command

Open the Linux terminal to check disk space, for instance type the following:

df -h

Notice how we used "-h", so we can have the results in "Human format". As a result, the size is in GB.

Filesystem      Size  Used Avail Use% Mounted on
devtmpfs         63G     0   63G   0% /dev
tmpfs            63G   77M   63G   1% /dev/shm
tmpfs            63G  4.1G   59G   7% /run
tmpfs            63G     0   63G   0% /sys/fs/cgroup
/dev/md3        1.8T  1.1T  741G  59% /
none             63G  6.5M   63G   1% /var/lve/dbgovernor-shm
/dev/md2        509M  251M  259M  50% /boot
/dev/nvme0n1p1  511M  5.9M  505M   2% /boot/efi
/dev/loop0      3.9G  1.2G  2.6G  31% /tmp
tmpfs            13G     0   13G   0% /run/user/1002
tmpfs            13G     0   13G   0% /run/user/1001

Use "df --help", to get more usage options.

Now we have an over view of what is taking so much space. It is time to dig in and go deeper using the "du" command, so we can find out what using using the disk space.

Find out what is filling up the disk space using du command

Use "du" command like this:

cd /

du -hsx * | sort -rh | head -10

As a result, It should display results like this:

959G    home
47G     usr
20G     mnt
15G     var
4.1G    run
2.4G    opt
1.2G    tmp
225M    boot
141M    root
89M     etc

How does it work?

"du -hsx * | sort -rh | head -10"

  • du
    estimate file space usage, therefore it is going to take some time as it goes into the details to make these calculations.
  • -hsx
    • -h or --human-readable.
      print sizes in human readable format, for example 1K 234M 5G.
    • -s or --summarize
      display only a total for each argument.
    • -x or --one-file-system
      skip directories on different file systems.
  • *
    Summarize disk usage of each FILE, recursively for directories.
  • |
    Also known as a control operator. It is used to separate one or more commands in a pipeline, for example, "Cat file1.txt | sort".
  • sort
    sort lines of text files.
  • -rh
    • -r or --reverse
      reverses the result of comparisons.
    • -h or --human-numeric-sort
      compare human readable numbers, for example 1K 2M 3G.
  • head
    output the first part of files.
  • -10
    show the top 10 results.

In conclusion, it is very easy to tack what is using the disk space in Linux. However, you still need knowledge of the commands. Most certainly more of my Linux articles will be found useful, so do not forget to check them out.

Are you facing problems?

Why don't you follow my Facebook page and ask me a question?