Shell script to sum up the space allocated to filesystems

Hi ,

I Would like to know the space allocated by adding up all the allocated space to group of filesystems ..

example ,

df -h|grep /db | awk '{ print $4 }'

---> giving me all the used space on the filesystem but need to know the total used space by adding up all the values

Assuming that you have more than one filesystem mounted on directories under /db (as in /db/database2 , /db/database2 , ...), try:

df /db/* | awk '{ avail += $4 } END {print avail}'

Assuming that you have more than one filesystem mounted on directories with names starting with db (as in /db1 , /db2 , ...), try:

df /db* | awk '{ avail += $4 } END {print avail}'

Note that there is no -h on the df invocations. Human readable output is fine if it is being read by a human. It is a nuisance if you're trying to add numbers (some of which are in terabytes, some of which are in gigabytes, some of which are in megabytes, ...).

Note that you can tell df which filesystems to process which makes it run faster since it doesn't have to process filesystems you don't care about and it gets rid of the need for the grep .

In both of the above suggestions, if you want to print the individual df output lines and print the total, change:

avail += $4

in the above scripts to:

print $4; avail += $4

if you just want to print the sizes with a total at the end, or to:

print; avail += $4

if you want to print the entire lines from df followed by the total available space on those filesystems.

Thanks very much!!

I would try it ,however i have other filesystem with archive too which needs to be added apart from db filesystems .i just need the sum of allocated space to filesystems.

I though of using the below

df -h | egrep 'db|archive'

Let me know any other alternative...

Please show us the output from the command:

df

and indicate which filesystems you want to include in the total.

And, do you just want the total, or do you want the individual filesystem sizes listed followed by the total?