Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to display the available disk space of a mount in xx% format,

For example:

sh-3.1$ df -h /opt/Application/Disk1/
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg00-LogVol09
                       57G   33G   22G  60% /opt/Application/Disk1/

I want to display only "%60"

share|improve this question
    
It's already displaying like that. Do you have an actual question? –  Ignacio Vazquez-Abrams Feb 9 '12 at 7:34
    
@IgnacioVazquez-Abrams He only wants to display "60%" (or "%60", dunno). Not the entire output. –  slhck Feb 9 '12 at 8:13

3 Answers 3

up vote 1 down vote accepted

You can try the following solution:

df -h /opt/Application/Disk1/ | awk '{print $4}' | tail -1

Here the awk '{print $4}' will print whatever appear in column 4 in your output and tail -1 will filter out only the last line.

share|improve this answer

I would like to display the available disk space of a mount in xx% format

...

I want to display only "%60"

The example you gave doesn't quite fit the question since the available disk space in this example would be 40%. In case you wanted just to filter out the Output for the used disk space, you want to go with Eugene S's answer. In case you wanted to express the available disk space in percent, you could use a modified version of it. Like this:

df /opt/Application/Disk1/ | awk '{print (100 -$5 )}' | tail -1 | sed 's/^/%/g'

Where awk '{print (100 -$5 )}' subtracts the percentage of the used disk space (which is in the 5th column in normal output of df) from 100, which results in the percentage of the available disk space. The trailing sed 's/^/%/g' just adds the symbol % in front of the output. To add % after the output use sed 's/$/%/g' instead.

share|improve this answer
#!/usr/bin/env python
import os, sys
st = os.statvfs(sys.argv[1])
free = st.f_bfree/st.f_blocks * 100
sys.stdout.write("%.f%%\n" % free)
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.