Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using awk and df (disk free) to show only mount name and space used

Tags:

bash

awk

What would be the correct CL sequence to execute a df -h and only print out the mount name and used space (percentage)? I'm trying to do a scripted report for our servers.

I tried

df -h | awk '{print $1 $4}'

which spits out

$df -h | awk '{print $1 $4}'
FilesystemAvail
/dev/sda164G
udev3.9G
tmpfs1.6G
none5.0M
none3.9G
none100M
/home/richard/.Private64G

How would you change this to add spacing? Am I selecting the right columns?

like image 588
Rick Avatar asked Dec 12 '22 15:12

Rick


2 Answers

Try this:

df -h | awk '{if ($1 != "Filesystem") print $1 " " $5}'

Or just

df -h | awk '{print $1 " " $5}'

if you want to keep the headers.

like image 164
Ansgar Wiechers Avatar answered May 15 '23 04:05

Ansgar Wiechers


You are almost there:

df -h | awk 'NR>1{print $1, $5}'
like image 37
perreal Avatar answered May 15 '23 03:05

perreal