The goal is to trigger an automatic alert when disk usage goes above a given threshold. So far I have only found the command df -hP /disk/path that returns disk usage. However, it returns lots of other information as well, as in the image below.

Screenshot of df command and result

I am looking for the most convenient way to retrieve the Use% statistic. Either through Regex or another Linux command.

It is different from existing question in that it only deals with extracting the right value from the df command while the other questions deal with this part, plus sending the alert as well. The top answer given to this question which I accepted is the most elegant way I have seen to extract the right value.


Try with this :

df -hP /disk/path | awk '{print $5}' |tail -1|sed 's/%$//g'
  • This is perfect, thank you! Seems like I should really learn about awk and sed if I were to work with Linux more. Feb 22 '17 at 14:05
  • @KarolisRamanauskas If helped upvote it and mark it as answered.
    – Rakesh.N
    Feb 22 '17 at 14:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.