1. Overview

There are various ways to ascertain disk space in Linux but most succinctly via three commands. These three commands are the du, df, and fdisk -l commands, alongside their options.

2.1 du command

The du command, which is an acronym for disk usage, estimates the disk usage of a file or directory. While it does not indicate the amount of disk space available, it is very useful in gauging hard drive usage. This is handy when determining the viability of certain solutions such as on-site backups, folder compression, and where to locate certain files or folders. The du command comes with options, the most useful being the -h, -a, and -s options:

  • du -h lists disk usage information in human-readable form, that is, in kilobytes and megabytes.
~$ du -h
0       ./.snapshots
1.5K    ./.config/configstore
2.0K    ./.config
512     ./.sage
1.5K    ./.ssh
14K     .
  • du -a displays disk usage of all files.
~$ du -a
1       ./.jupyter-blobs-v0.db
1       ./.smc
0       ./.snapshots
1       ./.bash_profile
3       ./.bashrc
2       ./.gitexcludes
1       ./.config/configstore/update-notifier-npm.json
2       ./.config/configstore
2       ./.config
1       ./Welcome to CoCalc.term
1       ./.gitconfig
1       ./.Welcome to CoCalc.term-0.term
1       ./.sage
1       ./.ssh/authorized_keys
2       ./.ssh
14      .
  • du -s lists disk usage for a particular file or directory.
~$ du -s
27  

When certain options are combined, better results are achieved. For example, du -ah will list the disk usage of all files in a human-readable form.

~$ du -ah
1.0K    ./.jupyter-blobs-v0.db
512     ./.smc
0       ./.snapshots
512     ./.bash_profile
2.5K    ./.bashrc
1.5K    ./.gitexcludes
1.0K    ./.config/configstore/update-notifier-npm.json
1.5K    ./.config/configstore
2.0K    ./.config
512     ./Welcome to CoCalc.term
1.0K    ./.gitconfig
1.0K    ./.Welcome to CoCalc.term-0.term
512     ./.sage
1.0K    ./.ssh/authorized_keys
1.5K    ./.ssh
14K     .

2.2 df command

The df command, which is an acronym for disk free, is the most useful command to estimate the amount of hard disk space available on a particular drive. Like the du command, df comes with options, the most useful being -h, -a, -T, and -i:

  • df -h displays disk space in human-readable form.
~$ df -h
Filesystem                                                                                        Size  Used Avail Use% Mounted on
overlay                                                                                           117G  8.1G  109G   7% /
tmpfs                                                                                              64M     0   64M   0% /dev
tmpfs                                                                                              13G     0   13G   0% /sys/fs/cgroup
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/opt                                      809G  667G   90G  89% /opt
10.105.159.225:/ubuntu2004_2020-08-18                                                             809G  667G   90G  89% /ext
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/libx32                                   809G  667G   90G  89% /libx32
tmpfs                                                                                              13G   24K   13G   1% /tmp
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/lib64                                    809G  667G   90G  89% /lib64
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/lib                                      809G  667G   90G  89% /lib
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/etc                                      809G  667G   90G  89% /etc
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/bin                                      809G  667G   90G  89% /bin
kucalc-default-project-f3ce3163-5f39-4c06-b0ad-07ac36f62c94                                       3.0G  128K  3.0G   1% /home/user
/var/lib/kubelet/pods/25cb6246-bdfc-44b3-942c-5844dfa8725e/volumes/cocalc~zfs/home/.zfs/snapshot  3.0G  128K  3.0G   1% /home/user/.snapshots
tmpfs                                                                                              13G  4.0K   13G   1% /secrets/gateway-public
/dev/sda1                                                                                         117G  8.1G  109G   7% /etc/hosts
tmpfs                                                                                              13G  4.0K   13G   1% /secrets/secret-token
shm                                                                                                64M     0   64M   0% /dev/shm
tmpfs                                                                                              13G     0   13G   0% /sys/firmware
  • df -a lists the file systems total usage even if the value is zero(0).
~$ df -a
Filesystem                                                                                       1K-blocks      Used Available Use% Mounted on
overlay                                                                                          121770540   8445232 113308924   7% /
proc                                                                                                     0         0         0    - /proc
tmpfs                                                                                                65536         0     65536   0% /dev
devpts                                                                                                   0         0         0    - /dev/pts
sysfs                                                                                                    0         0         0    - /sys
tmpfs                                                                                             13347324         0  13347324   0% /sys/fs/cgroup
cgroup                                                                                                   0         0         0    - /sys/fs/cgroup/devices
cgroup                                                                                                   0         0         0    - /sys/fs/cgroup/freezer
mqueue                                                                                                   0         0         0    - /dev/mqueue
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/opt                                     848297984 699066368  94121984  89% /opt
10.105.159.225:/ubuntu2004_2020-08-18                                                            848297984 699066368  94121984  89% /ext
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/libx32                                  848297984 699066368  94121984  89% /libx32
tmpfs                                                                                             13347324        24  13347300   1% /tmp
  • df -T lists disk usage with each block‚Äôs associated file system type.
~$ df -T
Filesystem                                                                                       Type    1K-blocks      Used Available Use% Mounted on
overlay                                                                                          overlay 121770540   8446492 113307664   7% /
tmpfs                                                                                            tmpfs       65536         0     65536   0% /dev
tmpfs                                                                                            tmpfs    13347324         0  13347324   0% /sys/fs/cgroup
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/opt                                     nfs4    848297984 699066368  94121984  89% /opt
10.105.159.225:/ubuntu2004_2020-08-18                                                            nfs4    848297984 699066368  94121984  89% /ext
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/libx32                                  nfs4    848297984 699066368  94121984  89% /libx32
tmpfs                                                                                            tmpfs    13347324        24  13347300   1% /tmp
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/lib64                                   nfs4    848297984 699066368  94121984  89% /lib64
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/lib                                     nfs4    848297984 699066368  94121984  89% /lib
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/etc                                     nfs4    848297984 699066368  94121984  89% /etc
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/bin                                     nfs4    848297984 699066368  94121984  89% /bin
kucalc-default-project-f3ce3163-5f39-4c06-b0ad-07ac36f62c94                                      zfs       3072384       128   3072256   1% /home/user
/var/lib/kubelet/pods/25cb6246-bdfc-44b3-942c-5844dfa8725e/volumes/cocalc~zfs/home/.zfs/snapshot fuse      3072384       128   3072256   1% /home/user/.snapshots
tmpfs                                                                                            tmpfs    13347324         4  13347320   1% /secrets/gateway-public
/dev/sda1                                                                                        ext4    121770540   8446492 113307664   7% /etc/hosts
  • df -i lists free and used inodes.
~$ df -i
Filesystem                                                                                         Inodes  IUsed    IFree IUse% Mounted on
overlay                                                                                          15482880 409497 15073383    3% /
tmpfs                                                                                             3336831     17  3336814    1% /dev
tmpfs                                                                                             3336831     17  3336814    1% /sys/fs/cgroup
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/opt                                            0      0        0     - /opt
10.105.159.225:/ubuntu2004_2020-08-18                                                                   0      0        0     - /ext
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/libx32                                         0      0        0     - /libx32
tmpfs                                                                                             3336831     12  3336819    1% /tmp
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/lib64                                          0      0        0     - /lib64
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/lib                                            0      0        0     - /lib
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/etc                                            0      0        0     - /etc
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/bin                                            0      0        0     - /bin
kucalc-default-project-f3ce3163-5f39-4c06-b0ad-07ac36f62c94                                       6144598     21  6144577    1% /home/user

Like the du command, when certain df options are combined, better results are achieved. For example, df -Th lists disk usage size in human-readable form, alongside block file systems.

~$ df -Th
Filesystem                                                                                       Type     Size  Used Avail Use% Mounted on
overlay                                                                                          overlay  117G  8.1G  109G   7% /
tmpfs                                                                                            tmpfs     64M     0   64M   0% /dev
tmpfs                                                                                            tmpfs     13G     0   13G   0% /sys/fs/cgroup
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/opt                                     nfs4     809G  667G   90G  89% /opt
10.105.159.225:/ubuntu2004_2020-08-18                                                            nfs4     809G  667G   90G  89% /ext
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/libx32                                  nfs4     809G  667G   90G  89% /libx32
tmpfs                                                                                            tmpfs     13G   24K   13G   1% /tmp
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/lib64                                   nfs4     809G  667G   90G  89% /lib64
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/lib                                     nfs4     809G  667G   90G  89% /lib
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/etc                                     nfs4     809G  667G   90G  89% /etc
10.105.159.225:/ubuntu2004_2020-08-18/linux/Ubuntu-20.04/bin                                     nfs4     809G  667G   90G  89% /bin
kucalc-default-project-f3ce3163-5f39-4c06-b0ad-07ac36f62c94                                      zfs      3.0G  128K  3.0G   1% /home/user
/var/lib/kubelet/pods/25cb6246-bdfc-44b3-942c-5844dfa8725e/volumes/cocalc~zfs/home/.zfs/snapshot fuse     3.0G  128K  3.0G   1% /home/user/.snapshots
tmpfs                                                                                            tmpfs     13G  4.0K   13G   1% /secrets/gateway-public
/dev/sda1                                                                                        ext4     117G  8.1G  109G   7% /etc/hosts

2.3 fdisk -l command

The fdisk -l command lists disk usage for the entire system including partitions. This command yields a larger picture overview of the disk usage of all partitions and devices associated with the system in question. In other words, all available systems listed in the /dev directory will have their disk usage details listed. Only the root administrator or a superuser with root privileges can run this command.

$ sudo fdisk -l
Disk /dev/loop0: 1.93 GiB, 2049204224 bytes, 4002495 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/sda: 931.53 GiB, 1000204886016 bytes, 1948781419 sectors
Disk model: WDC WD1003FZEX 
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: pc98
Disk identifier: CA273DCB-3421-7FD3-P6C1-91Y6456GA5BV

Device          Start        End    Sectors   Size Type
/dev/sda1        2048    1334363    1332315   670M Windows recovery environment
/dev/sda2     1334364    1889379     555015   280M EFI System
/dev/sda3     1889380    2156798     267418   128M Microsoft reserved
/dev/sda4     2156799 1186547541 1184390742 564.7G Microsoft basic data
/dev/sda5  1901347692 1902537762    1190070   853M Windows recovery environment
/dev/sda6  1902537763 1948783473   46245710  27.5G Microsoft basic data
/dev/sda7  1186547542 1901347691  714800149 331.2G Linux filesystem

Partition table entries are not in disk order.

3. Conclusion

While there are other commands and techniques for determining disk usage, the du, df, and fdisk -l commands are the most useful and direct.

Leave a Reply

Your email address will not be published. Required fields are marked *