Languages
[Edit]
EN

Bash - print free disk space

10 points
Created by:
martineau
450

In this short article, we would like to show how to print currently free and used space under Linux/Unix using Bash.

Quick solution (run the following command):

df -h

Where -h causes printing in human-readable format (KB, MB, GB).

Example output:

Filesystem      Size  Used Avail Use% Mounted on
udev            2.0G     0  2.0G   0% /dev
tmpfs           395M   40M  356M  11% /run
/dev/sda1        50G   48G     0 100% /
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
tmpfs           395M     0  395M   0% /run/user/1001

Summary:

  1. at first, we need to find mounting point that keeps data
    (in our case all tings are stored in the same place: /),
  2. we can see the device /dev/sda1 mounted as / has capacity 50GB, is used 48GB, is available 0MB.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join