在linux下如果要查找包含某个关键字的文件,如要在nagios目录下搜索带有关键字“store-rd-sys”的文件,在终端下运行命令:
/usr/local/nagios/etc/* (nagios目录)
法1:grep -r “关键字” 路径
[[email protected] ~]#grep -r "store-rd-sys" /usr/local/nagios/etc/cfgs/
/usr/local/nagios/etc/cfgs/bjd-physicalmachine-host.cfg: hostgroup_name store-rd-sys
/usr/local/nagios/etc/cfgs/bjd-physicalmachine-host.cfg: alias store-rd-sys
法2:find /usr/local/nagios/etc/cfgs/ –type f |xargs grep “store-rd-sys”
[[email protected] ~]#find /usr/local/nagios/etc/cfgs/ -type f |xargs grep "store-rd-sys"
/usr/local/nagios/etc/cfgs/bjd-physicalmachine-host.cfg: hostgroup_name store-rd-sys
/usr/local/nagios/etc/cfgs/bjd-physicalmachine-host.cfg: alias store-rd-sys