There are several questions and answers on askubuntu about seeing disk space from the command line.
Naturally, df
is the go-to tool for this.
However I want a script at login to raise an alert if the free disk space is below some threshold.
Unfortunately df
seems to use arbitrarily sized columns and I'm not sure how to extract just the value from the column I'm interested in.
For example:
$ df /dev/mapper/root
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/root 2563092 1649968 763212 69% /
$ df /dev/mapper/root | tail -n 1
/dev/mapper/root 2563092 1649968 763212 69% /
$ df /dev/mapper/root | tail -n 1 | cut -d ' ' -f 9
763212
Really I want the fourth column, yet I must ask for the ninth.
Is there an easier way to either extract the column's value from df
's output, or another way altogether to access this value.