概述
对linux df 输出内容进行格式化
添加/usr/bin/dfb文件
[root@oracle6 ~]# more /usr/bin/dfb
{
if (split($0, f) == 1) {
getline
split($0, rest)
for (i = 1; i <= NF; i++) f[i+1] = rest[i]
}
printf ("%-31s %12s %10s %10s %5s %sn", f[1], f[2], f[3], f[4], f[5], f[6])
}
df后面添加相应的参数
[root@oracle6 ~]# df | awk -f /usr/bin/dfb
Filesystem 1K-blocks Used Available Use% Mounted
/dev/mapper/vg_oracle6-lv_root 51606140 47447460 1537240 97% /
tmpfs 1962952 1028432 934520 53% /dev/shm
/dev/sda1 495844 37911 432333 9% /boot
/dev/mapper/vg_oracle6-lv_home 150309116 51456088 91217676 37% /home
[root@oracle6 ~]#
[root@oracle6 ~]# df -h | awk -f /usr/bin/dfb
Filesystem Size Used Avail Use% Mounted
/dev/mapper/vg_oracle6-lv_root 50G 46G 1.5G 97% /
tmpfs 1.9G 1005M 913M 53% /dev/shm
/dev/sda1 485M 38M 423M 9% /boot
/dev/mapper/vg_oracle6-lv_home 144G 50G 87G 37% /home
在alias中添加命令
[root@oracle6 ~]# alias dfk='df | awk -f /usr/bin/dfb'
[root@oracle6 ~]# alias dfg='df -h | awk -f /usr/bin/dfb'
[root@oracle6 ~]#
[root@oracle6 ~]# dfk
Filesystem 1K-blocks Used Available Use% Mounted
/dev/mapper/vg_oracle6-lv_root 51606140 47447464 1537236 97% /
tmpfs 1962952 1028432 934520 53% /dev/shm
/dev/sda1 495844 37911 432333 9% /boot
/dev/mapper/vg_oracle6-lv_home 150309116 51456088 91217676 37% /home
[root@oracle6 ~]#
[root@oracle6 ~]# dfg
Filesystem Size Used Avail Use% Mounted
/dev/mapper/vg_oracle6-lv_root 50G 46G 1.5G 97% /
tmpfs 1.9G 1005M 913M 53% /dev/shm
/dev/sda1 485M 38M 423M 9% /boot
/dev/mapper/vg_oracle6-lv_home 144G 50G 87G 37% /home
这样就可以很好的显示和阅读df的输出了.
添加/usr/bin/dfb文件
[root@oracle6 ~]# more /usr/bin/dfb
{
if (split($0, f) == 1) {
getline
split($0, rest)
for (i = 1; i <= NF; i++) f[i+1] = rest[i]
}
printf ("%-31s %12s %10s %10s %5s %sn", f[1], f[2], f[3], f[4], f[5], f[6])
}
df后面添加相应的参数
[root@oracle6 ~]# df | awk -f /usr/bin/dfb
Filesystem 1K-blocks Used Available Use% Mounted
/dev/mapper/vg_oracle6-lv_root 51606140 47447460 1537240 97% /
tmpfs 1962952 1028432 934520 53% /dev/shm
/dev/sda1 495844 37911 432333 9% /boot
/dev/mapper/vg_oracle6-lv_home 150309116 51456088 91217676 37% /home
[root@oracle6 ~]#
[root@oracle6 ~]# df -h | awk -f /usr/bin/dfb
Filesystem Size Used Avail Use% Mounted
/dev/mapper/vg_oracle6-lv_root 50G 46G 1.5G 97% /
tmpfs 1.9G 1005M 913M 53% /dev/shm
/dev/sda1 485M 38M 423M 9% /boot
/dev/mapper/vg_oracle6-lv_home 144G 50G 87G 37% /home
在alias中添加命令
[root@oracle6 ~]# alias dfk='df | awk -f /usr/bin/dfb'
[root@oracle6 ~]# alias dfg='df -h | awk -f /usr/bin/dfb'
[root@oracle6 ~]#
[root@oracle6 ~]# dfk
Filesystem 1K-blocks Used Available Use% Mounted
/dev/mapper/vg_oracle6-lv_root 51606140 47447464 1537236 97% /
tmpfs 1962952 1028432 934520 53% /dev/shm
/dev/sda1 495844 37911 432333 9% /boot
/dev/mapper/vg_oracle6-lv_home 150309116 51456088 91217676 37% /home
[root@oracle6 ~]#
[root@oracle6 ~]# dfg
Filesystem Size Used Avail Use% Mounted
/dev/mapper/vg_oracle6-lv_root 50G 46G 1.5G 97% /
tmpfs 1.9G 1005M 913M 53% /dev/shm
/dev/sda1 485M 38M 423M 9% /boot
/dev/mapper/vg_oracle6-lv_home 144G 50G 87G 37% /home
这样就可以很好的显示和阅读df的输出了.
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24237320/viewspace-1993384/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/24237320/viewspace-1993384/
最后
以上就是感性学姐为你收集整理的[Shell] linux df 输出内容格式化的全部内容,希望文章能够帮你解决[Shell] linux df 输出内容格式化所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复