利用alias+函数,改变命令执行参数,实现netstat -antp转-ant等

某些特定的情况下,需要转换命令执行参数规避部分问题。

如: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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值