AskWael

Menu

Category: Linux

Linux Disk Space Usage Tracking

Language

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?

How to upgrade pip?

Language

This article will explain how to upgrade pip on Linux operating systems and walk you through the process. You can find more articles on Linux here.

How to upgrade pip on Linux?

Upgrading pip on Linux is easy. Before we begin we need to find out which version of pip is running on the operating system. This step is important before upgrading, because we will do it again once the upgrade is complete and compare the output. This will help us verify that upgrading pip has been done successfully.

Open your terminal and type the below:

$ pip -V

The result will be the following:

$ pip -V
pip 9.0.1 from from /usr/lib/python3.9/site-packages/pip (python 3.9)

We can now proceed with upgrading pip using the following command:

$ pip install --upgrade pip

The upgrade process will begin by installing some files, and once the installation is complete. You will receiving the following message:

$ pip install --upgrade pip
Successfully installed pip-21.3.1

Keep in mind that the version number might differ for you depending on when you performed this upgrade. During this upgrade, the latest version was 21.3.1.

Now lets verify that we are running the upgraded version of pip, by typing the following command:

$ pip -V

The result will be the following:

$ pip -V
pip 21.3.1 from from /usr/lib/python3.9/site-packages/pip (python 3.9)

This means that we have upgraded from pip 9.0.1 to pip 21.3.1 successfully.

How to perform the upgrade on Linux virtual environment?

Upgrading pip on python virtualenv is very simple and straightforward. Open your terminal and activate the virtual environment. Once you are in the virtual environment, you can follow the steps above. Upgrading pip on virtualenv is the same as upgrading it on Linux.

Are you facing problems?

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