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 1What 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 -hAnother way to do this is with the lsblk command
-loutput in list format-nskip the header line-bprint in bytes-ooutputs specified column(s)FSAVAILprint file-system size available/free
lsblk -l -n -b -o FSAVAIL | grep -v ^$ | \
awk '{sum+=$1} END{print sum}' | numfmt --to=iecUse grep to exclude empty lines, awk to sum the first column, and finally numfmt to convert bytes to "human readable" format.