Reputation: 591
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?
Upvotes: 5
Views: 20791
Reputation: 18359
The issues with your code are what input to process, and how to format the output.
As an example, this awk selects records that have a % symbol at the end of field five, and put a space between the two output fields.
df -h | awk '$5 ~ /\%$/ {print $1 " " $5 }'
Everything else is just refining those two things.
Upvotes: 1
Reputation: 200483
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.
Upvotes: 11