Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to get the names of all disks with at least 90% usage, using this oneliner:

df -Pm | awk '+$5 >= 90 {print}'

But it doesn't show the "100% usage" case, I need to grep for "100%". Why doesn't it work correctly?

share|improve this question
1  
what version of awk are you running? –  glenn jackman Aug 30 '11 at 13:32
    
I just dd'd my disk usage so I had both 100% used on one fs and between 90 and 100 on another and I got both reported. Used your exact syntax. –  Kevin M Sep 7 '11 at 17:22

3 Answers 3

Could you give us an example output from df -Pm ? I'm sure most of us don't have 100% or their disk space used ;)

i just tested by hacking up my df's output and your awk part seems to be fine.

$ cat /tmp/1 | awk '+$5 >= 90 {print}'
tmpfs                        1978         1      1978     101% /dev/shm
tmpfs                        1978         1      1977     100% /run
share|improve this answer

I assume the problem is the percentage sign, which probably turns the >= into a string comparison. Add 0 to $5 before doing the comparison, this way you force $5 to be interpreted as a number:

df -P | awk '0 + $5 >= 90 { print }'
share|improve this answer

I suggest a slightly alternate approach. A little math never hurt anyone.

df -Pml | tail -n +2 | awk '{if ($4/$2 < 0.1) print $1,"is getting full."}'

This will calculate wether the filesystem is less than 10% free (which is actually how df displays it, even though the column is labeled "Used", and the -l prints only local filesystems). Throwing in tail -n +2 skips the header.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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