share
Unix & LinuxOutputing only number in df command
[0] [3] rktech
[2020-04-18 17:51:05]
[ debian disk-usage ]
[ https://unix.stackexchange.com/questions/580965/outputing-only-number-in-df-command ]

I have a disk mounted on /dev/xxx. If I use only df, it returns this:

Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/xxx       125829120 43861888  81967232  35% /
devtmpfs         4194304        0   4194304   0% /dev
...

I need to get only:

a) number of 1K-blocks

b) used space

How to do that?

You don't want the source device or mountpoint? - Jeff Schaller
You don't have a disk mounted on /dev/xxx. You have /dev/xxx mounted on /. - Kusalananda
@Kusalananda that is what I've figured - rktech
[+2] [2020-04-18 18:11:12] JRFerguson
df /dev/sda1 --output=source,size,used

...gives a terse summary.


1
[+1] [2020-04-18 18:02:33] GMaster [ACCEPTED]

Here you go

df /dev/xxx | awk 'END { print $2, $3 }' 

2
[0] [2020-04-18 18:02:31] Stalin Vignesh Kumar

Using awk , if you want to do some process inside the block .

For only number of K-blocks and used space :

df | awk 'BEGIN { getline } { print $2,$3 }' 

If you want With Filesystem name :

df | awk 'BEGIN { getline }  { print $1,$2,$3 }'

For only the disk /dev/xxx

df /dev/xxx | awk 'BEGIN { getline }  { print $2,$3 }'

3