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.


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

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.