Total space Determination

Hi experts,

[root@localhost root]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda9 3.8G 1.7G 2.0G 46% /
none 369M 0 369M 0% /dev/shm
/dev/hda10 2.0G 33M 1.8G 2% /tmp
/dev/hda12 1.4G 1.2G 260M 82% /usr

I used df -h to determine the file system usage as shown above . i want to know how much of total space is available in OS for later use in Operating system.

OS used is Red hat linux 8.0

Regards,
Balaji

With awk:

df -h | 
awk 'NR==1{next}
split($4,f,"G")>1{$4=f[1]*1024}
{sub("M","",$4);s+=$4}
END{print "Available: " s "M"}'

Regards

i cannot understand this coding.Could you please explain me briefly on this?

Thanks $ Regards,
William

awk 'NR==1{next}

Skip the 1st line.

split($4,f,"G")>1{$4=f[1]*1024}

The split function is used to search for a "G" in the 4th field and to separate the last letter from the numeric value. If the last letter of the 4th field is a "G", f[1] holds the value of the available Gigabytes, f[2] holds the "G" and the return code is 2 otherwise the return code is 1.
If the returncode > 1 the value is multiplied with 1024 (to Megabytes) and assigned to the 4th field.

{sub("M","",$4);s+=$4}

The sub function deletes the "M" from field $4 (if it's available). The next statement adds the value of the 4th field to the variable s.

END{print "Available: " s "M"}'

After processing the last line, print the sum of available Megabytes.

Regards