Linux df 电子邮件中的良好输出格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10650207/
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
df nice output format in emails
提问by Sergii Shevchyk
I sent emails with space usage information.
我发送了包含空间使用信息的电子邮件。
df -Ph | mailx -s "disk usage" [email protected]
df -Ph | mailx -s "disk usage" [email protected]
But when I read an email it looks like this:
但是当我阅读一封电子邮件时,它看起来像这样:
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 2.0G 372M 1.6G 20% /
tmpfs 32G 12G 20G 38% /dev/shm
/dev/sda1 248M 28M 208M 12% /boot
/dev/mapper/sys-home 4.0G 308M 3.6G 8% /home
/dev/mapper/sys-tmp 2.0G 3.7M 1.9G 1% /tmp
/dev/mapper/sys-rcv 247G 130G 114G 54% /flash_recovery_area
/dev/mapper/sys-usr 4.0G 2.6G 1.4G 66% /usr
/dev/mapper/sys-var 2.0G 291M 1.6G 16% /var
/dev/mapper/orcl-u01 493G 331G 162G 68% /u01
/dev/mapper/orcl-ora 640G 588G 53G 92% /oradata
/dev/sdc1 916G 602G 268G 70% /mnt/backup
/dev/sdb2 516G 241G 250G 50% /oradata/ods
Any ideas, how can I preformat it order to align the column in the table?
任何想法,我如何预先格式化它以对齐表格中的列?
I want it prettily formatted:
我希望它的格式很好:
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 2.0G 372M 1.6G 20% /
tmpfs 32G 12G 20G 38% /dev/shm
/dev/sda1 248M 28M 208M 12% /boot
/dev/mapper/sys-home 4.0G 308M 3.6G 8% /home
/dev/mapper/sys-tmp 2.0G 3.7M 1.9G 1% /tmp
/dev/mapper/sys-rcv 247G 130G 114G 54% /flash_recovery_area
/dev/mapper/sys-usr 4.0G 2.6G 1.4G 66% /usr
/dev/mapper/sys-var 2.0G 291M 1.6G 16% /var
/dev/mapper/orcl-u01 493G 331G 162G 68% /u01
/dev/mapper/orcl-ora 640G 588G 53G 92% /oradata
/dev/sdc1 916G 602G 268G 70% /mnt/backup
/dev/sdb2 516G 241G 250G 50% /oradata/ods
采纳答案by raittes
Try column -t
尝试 column -t
df -Ph | column -t
回答by Peter G.
I would first verify that my email program is using a fixed width font. If that is not an option, perhaps you can convert the df
output to HTML and use <pre></pre>
tags to trigger the email program to use fixed fonts.
我会首先验证我的电子邮件程序是否使用了固定宽度的字体。如果这不是一个选项,也许您可以将df
输出转换为 HTML 并使用<pre></pre>
标签来触发电子邮件程序使用固定字体。
回答by Ulrich Schwarz
Hooray for perl
:
万岁perl
:
df -Ph | perl -ne 'chomp; printf "\n%-40s %8s %8s %8s %8s %-20s", split / +/, $_, 6 ; '
might do vaguely what you want. (The numbers are the column widths, negative means left-justified.)
可能会模糊地做你想要的。(数字是列宽,负数表示左对齐。)