0

I tried this by typing df -k ., I get the following:

Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       16512936 8650196   7023932  56% /

I tailed the last statement and gwt 4th block . but if file system name is long ,then

df -k .

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_vomesx6vm24-lv_root
                      51606140   1963476  47021224   5% /

is failing to get fouth block as fourth block is 5% . How to get available space in any situation ?

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
Niraj Nandane
  • 1,318
  • 1
  • 13
  • 24
  • If you want in gbs or mbs then use df -m or df -g. see man df – Nachiket Kate Jan 05 '15 at 09:46
  • what i am doing is tailing the last line and then extracting the fourth field(available),but problem is if file system name is long say,/dev/dfdsfidfidfdfdf then what unix do is print the details on new line ,thus it giving me 56% as a output – Niraj Nandane Jan 05 '15 at 09:53
  • how to get exact available disk space only in any situation ? – Niraj Nandane Jan 05 '15 at 09:54
  • Niraj: Since your problem is long device name causing df to fail to print in correct/readable format, I suggest you change the title and the descriptions. And I suggest you give an example, OR do you mean the printing you shown above is missing /dev/dfdsfidfidfdfdf? Please show us the results with your long device name. – Robin Hsu Jan 05 '15 at 10:06
  • df -k . Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/vg_vomesx6vm24-lv_root 51606140 1963476 47021224 5% / – Niraj Nandane Jan 05 '15 at 10:47
  • df -k . Filesystem 1K-blocks Used Available Use% Mounted on/dev/mapper/vg_vomesx6vm24-lv_root 51606140 1963476 47021224 5% / – Niraj Nandane Jan 05 '15 at 10:47
  • Pretty related: [Get free disk space with df to just display free space in kb?](http://stackoverflow.com/q/19703621/1983854) – fedorqui Jan 05 '15 at 11:43

2 Answers2

1

I'm not sure what you are exactly asking for, but you can tell df to show just what you need, eg.:

$ df -k --output=used /dev/mapper/vg_crypto-lv_root
    Used
28287028

Search for FIELD_LIST in df manpage for the details.

marbu
  • 1,939
  • 2
  • 16
  • 30
0

use below

df -P|awk '{print $4}'
Shantanu
  • 186
  • 1
  • 8