bash 使用 awk 和 df(无磁盘)仅显示挂载名称和使用的空间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16045502/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using awk and df (disk free) to show only mount name and space used
提问by Rick
What would be the correct CL sequence to execute a df -hand only print out the mount name and used space (percentage)? I'm trying to do a scripted report for our servers.
执行 adf -h并仅打印出安装名称和已用空间(百分比)的正确 CL 序列是什么?我正在尝试为我们的服务器编写脚本报告。
I tried
我试过
df -h | awk '{print $1 $4}'
df -h | awk '{print $1 $4}'
which spits out
吐出来的
$df -h | awk '{print }'
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?
你会如何改变它以增加间距?我是否选择了正确的列?
回答by Ansgar Wiechers
Try this:
尝试这个:
df -h | awk '{if ( != "Filesystem") print " " }'
Or just
要不就
df -h | awk '{print " " }'
if you want to keep the headers.
如果你想保留标题。
回答by perreal
You are almost there:
你快到了:
df -h | awk 'NR>1{print , }'
回答by janm
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 ' ~ /\%$/ {print " " }'
Everything else is just refining those two things.
其他的都只是提炼这两点而已。

