Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I use df -h, I get the following output:

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/VolGroup00-LogVol00 59G 2.2G 54G 4% /

/dev/sda1 122M 38M 78M 33% /boot

tmpfs 1.1G 0 1.1G 0% /dev/shm

                   11T  8.4T  2.1T  81% /storage4

                   15T  8.9T  5.9T  61% /storage1

/dev/mapper/patha 5.0T 255G 4.8T 5% /storage5_vol0

/dev/mapper/pathb 5.0T 195G 4.9T 4% /storage5_vol1

/dev/mapper/pathc 5.0T 608G 4.5T 12% /storage5_vol2

I want to write a script that gets the value of Avail column on a specific storage.

I used to use

df -k /storage_name | tail -1 | awk '{print $3}'

But the FileSystem column can have a value or not .. which would change the variable of my script from $3 to $4.

How can I get the Avail on a single command line even if there are no values on the previous columns?

share|improve this question
Please don't cross-post. – Dennis Williamson Mar 15 '11 at 16:46
up vote 5 down vote accepted

Use df's -P option for "portability" or "POSIX" output and change to the 4th field for the available count.

df -kP /storage_name | tail -1 | awk '{print $4}'

share|improve this answer

Your Answer


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.