hpfinder (linux 文件内容查找 )

来源:互联网 发布:葫芦线切割3b编程实例 编辑:程序博客网 时间:2024/06/05 09:05


可实现在不同目录下的递归查找文件内容


源码:

#!/bin/shif [ -n "$2" ];thenpath=$2elsepath=`pwd`ficd $pathfor i in `ls`do log=$path/$iif [ -d "$log" ];thencd $logfor j in `ls`doif [ -f "$j" ];thenrs=`cat $j|grep $1`if [ -n "$rs" ];thenecho ==== in `pwd`/$j =====cat $j|grep $1echo ==== end =====echofielsenpath=`pwd`hpfinder $1 $npath fidoneelsers=`cat $log|grep $1`if [ -n "$rs" ];thenecho ==== in $log =====cat $log|grep $1echo ==== end =====echofifidone


使用方法:

./hpfinder 查找的内容 [查找目录]



示例:

[root@EM-FGXTT2X test]# pwd/tmp/test[root@EM-FGXTT2X test]# tree ..|-- a|-- b|-- c`-- dir2    |-- a    |-- b    `-- c1 directory, 6 files

在目录/tmp/test 下的文件a b c,和子目录dir2下的a b c 内容下

[root@EM-FGXTT2X test]# cat a b cone line1two line2one line1two line2aaaaaaaaabbbbbbbbbline3


执行

hpfinder line

结果:

[root@EM-FGXTT2X test]# hpfinder line ==== in /tmp/test/a =====one line1two line2==== end ========= in /tmp/test/b =====one line1two line2==== end ========= in /tmp/test/c =====line3==== end ========= in /tmp/test/dir2/a =====one line1two line2==== end ========= in /tmp/test/dir2/b =====one line1two line2==== end ========= in /tmp/test/dir2/c =====line3==== end =====




详情见:https://github.com/HappyAaron/hpfinder

0 0