Since you know what partition you are looking for, just specify it in the df
command:
df -m /
Also, you can use the --output
option to define what columns you want to show. In this case, "available", whic
df -m --output=avail /
From man df
:
--output[=FIELD_LIST]
use the output format defined by FIELD_LIST, or print all fields if
FIELD_LIST is omitted.
...
FIELD_LIST is a comma-separated list of columns to be included. Valid
field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail',
'ipcent', 'size', 'used', 'avail', 'pcent' and 'target' (see info
page).
Note, however, that this --output
option may be just available in GNU. Also, it prints the header, so you may want to pipe to tail -1
to get the last line.
df -m | awk 'NR==2{print $4}'
?awk '$NF=="/" {print $4}'
is more robust...df
has the--output
flag that can be very useful in such situations. e.gdf -m / --output=avail |tail -n1
or if you want to use awkdf -m / --output=avail |awk 'getline'
And if you want to use purely bash syntax:read -d '' -ra df_arr < <(LC_ALL=C df -mP /); echo "${df_arr[10]}"