How could I check total free storage capacity left on my system among multiple hdd's?

I have 15 SATA hard drives attached to my computer and having to go through them one by one, writing down the free space and then summing everything up is not ideal.

Is there a command or a combination of commands that could do that? Ideally where I could pass something like /dev/sd* since I do not want to include the nvme drives.

2 Answers

EDIT: I should read man pages more often. It is as simple as

df --total -h /dev/sd*

Okay I figured out something

df --output=avail /dev/sd* | tail -n +2 | datamash sum 1

What this basically does is listing mounted disks and displaying only the available space as output, then using tail for removing the first line which is the column title Avail then finally summing the numbers with datamash.

Keep in mind with the df command in order to exclude virtual RAM disk entries such as /dev, use the -x parameter:

df -x tmpfs -x devtmpfs --total -h

Another way to do this is with the lsblk command

  • -l output in list format
  • -n skip the header line
  • -b print in bytes
  • -o outputs specified column(s)
  • FSAVAIL print file-system size available/free
lsblk -l -n -b -o FSAVAIL | grep -v ^$ | \
awk '{sum+=$1} END{print sum}' | numfmt --to=iec

Use grep to exclude empty lines, awk to sum the first column, and finally numfmt to convert bytes to "human readable" format.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like