Getting information about how much disk space your Linux installation is taking up is very easy. The du command can print disk usage.
This example is used on my WSL2 Kali Linux installation.
┌──(john㉿DESKTOP-PF01IEE)-[~] └─$ sudo du -hl --exclude=/{proc,sys,dev,run,mnt} / | awk 'END {print $1 " Space used on " $2}' 6.5G Space used on / |
And this is on a Ubuntu headless server. This one-liner excludes virtual filesystems like /dev/ and /proc, also /mnt. This just calculates the total filesystem usage of all files on your Linux installation.
653 jason@jason-Lenovo-H50-55:~$ sudo du -hl --exclude=/{proc,sys,dev,run,mnt} / | awk 'END {print $1 " Space used on " $2}' [sudo] password for jason: 83G Space used on / |
This version is very good also. This is much simpler than using grep and complicated commands. Awk makes this much easier.
jason@jason-Lenovo-H50-55:~$ sudo du -hl --exclude=/{proc,sys,dev,run,mnt} / | awk 'END {print "There is " $1 " of space used on " $2}' There is 83G of space used on / |
This version works just fine as well, but it is more complicated and this is not as easy to edit.
┌──(john㉿DESKTOP-PF01IEE)-[~] └─$ sudo du -hl --exclude=/{proc,sys,dev,run,mnt} / | tail -n 1 | grep -o '^[^/]*' [sudo] password for john: 6.5G |
To see the total free space on your Linux system, this command will do it.
jason@jason-Lenovo-H50-55:~$ df -Hla / Filesystem Size Used Avail Use% Mounted on /dev/sda1 984G 81G 853G 9% / |
And to see certain columns in the df output, use the –output parameter.
jason@jason-Lenovo-H50-55:~$ df -Hla --output=itotal,used,avail,size,pcent / Inodes Used Avail Size Use% 62M 81G 853G 984G 9% |
This is a great way to customize the output of this useful utility.