某些特定的情况下,需要转换命令执行参数规避部分问题。
如:netstat -ant的执行效率高于netstat -antp,检查如果使用netstat -antp命令,转换为netstat -ant并不影响检查结果,可以通过转换来提高效率,避免因为执行时间造成检查失败
实现命令:
alias netstat='f(){ netstat ${@/-antp/-ant}; unset -f f; }; f'
//unset -f 删除已经定义的变量或者函数,避免影响其他程序
//最后的f调用了,临时函数
[root@localhost ~]# which netstat
alias netstat='f(){ netstat ${@/-antp/-ant}; unset -f f; }; f'
转换后结果:
[root@localhost ~]# netstat -antp | grep ':22' | grep LIST
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp6 0 0 :::22 :::* LISTEN
转换前结果:
[root@localhost ~]# netstat -antp | grep ':22' | grep LISTE
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1479413/sshd: /usr/
tcp6 0 0 :::22 :::* LISTEN 1479413/sshd: /usr/