[英]Using awk and df (disk free) to show only mount name and space used
What would be the correct CL sequence to execute a df -h
and only print out the mount name and used space (percentage)? 执行
df -h
并且只打印出挂载名称和已用空间(百分比)的正确CL序列是什么? 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?
我选择了正确的专栏吗?
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. 如果你想保留标题。
你快到了:
df -h | awk 'NR>1{print $1, $5}'
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. 例如,此awk选择在字段5的末尾具有%符号的记录,并在两个输出字段之间放置一个空格。
df -h | awk '$5 ~ /\%$/ {print $1 " " $5 }'
Everything else is just refining those two things. 其他一切只是改进这两件事。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.