Thursday, February 16, 2012

AWK instead of AWK & grep

Say I want to use df -h to see my available disk space, however I would only like the output the space currently available for rootfs.

I could do:

df -h | grep rootfs | awk '{print $2}'

This however, is a waste of resources because you are piping unnecessarily many times and it is also not very elegant, the following way is more preferable:

df -h | awk '/rootfs/ {print $2}'

No comments:

Post a Comment