You can do it with the shell alone (works in bash, dash, ksh, zsh):
df . | (read a; read a b; echo "$a")
Or if output is not needed (result will be kept in $a) and your shell supports process substitution (like bash, zsh):
{ read; read a b;}< <(df .)
And here are some comparisons with the other solutions' speed:
# pure shell solution 1
bash-4.2$ time for i in $(seq 500); do df . | (read a; read a b; echo "$a"); done > /dev/null
1.899
(dash) $ time -f '%e' dash -c 'for i in $(seq 500); do df . | (read a; read a b; echo "$a"); done > /dev/null'
1.05
(ksh) $ time for i in $(seq 500); do df . | (read a; read a b; echo "$a"); done > /dev/null
0m1.16s real 0m0.02s user 0m0.12s system
(zsh) manatwork% time (for i in $(seq 500); do df . | (read a; read a b; echo "$a"); done > /dev/null)
1.51s
# pure shell solution 2
bash-4.2$ time for i in $(seq 500); do { read; read a b;}< <(df .); done
1.192
(zsh) manatwork% time (for i in $(seq 500); do { read; read a b;}< <(df .); done)
3.51s
# other solutions
bash-4.2$ time for i in $(seq 500); do df . | tail -1 | cut -f 1 -d " "; done > /dev/null
1.405
bash-4.2$ time for i in $(seq 500); do df . | sed '2!d' | awk '{print $1}'; done > /dev/null
5.407
bash-4.2$ time for i in $(seq 500); do df . | sed -n '2{s/ .*$//;p}'; done > /dev/null
1.767
bash-4.2$ time for i in $(seq 500); do df . | sed '2!d' | awk '{print $1}'; done > /dev/null
3.334
bash-4.2$ time for i in $(seq 500); do df . | gawk 'NR==2{print $1}'; done > /dev/null
3.013
bash-4.2$ time for i in $(seq 500); do df . | mawk 'NR==2{print $1}'; done > /dev/null
1.747
bash-4.2$ time for i in $(seq 500); do df . | perl -nae 'print$F[0]if$.==2'; done > /dev/null
2.752
(Not compared with the stat solution as it not works here.)
dfoutput is not difficult:df . | tail -1 | cut -f 1 -d " "But maybe there are better solutions. – jofel Feb 22 at 12:35stat, which gives a device field, but you'll have to translate that back. May be much faster though, especially ifdfis taking forever to get usage over, e.g., NFS. – derobert Feb 22 at 13:37stat -f "%Sdf" .seems quicker - it decreased the time from 1.8s to 1.7 over 500 iterations. I have no network concerns, but this is a top tip, thanks. – antonyh Feb 22 at 14:45