Linux Listing Disk Usage
If you are administering a Linux machine over the course of your time you will almost certainly need to get information of how much disk space is available on the drive or drives that you have mounted. This is a trivial task to accomplish however if you do not know the command you wont get far.
DF Command
The df
or "disk free" command is what you need in your life! As described in the linux man pages "df displays the amount of disk space available on the file system containing each file name argument". One of the arguments it accepts is -h
which lists the output in a human readable format in powers of 1024 Bytes. An example output from one of my machines is below.
$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 796M 1.2M 795M 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 24G 12G 12G 50% /
tmpfs 3.9G 216K 3.9G 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/loop1 56M 56M 0 100% /snap/core18/2538
/dev/loop3 62M 62M 0 100% /snap/core20/1611
/dev/loop2 62M 62M 0 100% /snap/core20/1593
/dev/loop4 71M 71M 0 100% /snap/lxd/21029
/dev/loop5 68M 68M 0 100% /snap/lxd/22753
/dev/loop6 47M 47M 0 100% /snap/snapd/16292
/dev/loop7 47M 47M 0 100% /snap/snapd/16010
/dev/sda2 974M 205M 702M 23% /boot
/dev/loop8 56M 56M 0 100% /snap/core18/2560
tmpfs 796M 0 796M 0% /run/user/1973028261
$
As you can see it lists the filesystem, overall size, space used, space available, percentage used, and mount location.
With this output looking at the the 3rd entry in the table.
/dev/mapper/ubuntu--vg-ubuntu--lv 24G 12G 12G 50% /
I can easily tell that the root of my file system and all directories under it unless specified somewhere in this output has a total of 24G capacity and is half full.
So as you can see this is a fairly trivial task to accomplish but you will find yourself using it all the time when forecasting and troubleshooting.