LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 698|回复: 2

一个递归搜索 文件包函字符的 脚本

[复制链接]
发表于 2006-12-12 21:41:38 | 显示全部楼层 |阅读模式

  1. #!/bin/sh
  2. #Useage find 路径 字符串

  3. find_dir ()
  4. {
  5.         local dir_f=`echo $1|sed -e 's/\/$//g'`
  6.         grep -n $2 $dir_f/*
  7.         for name in `ls $1`
  8.         do
  9.                 temp_name="$dir_f/$name"
  10.                 if [ -d $temp_name ]; then       
  11.                         #echo $temp_name
  12.                         grep -n $2 $temp_name/*
  13.                         find_dir $temp_name $2
  14.                 fi
  15.         done

  16. }

  17. find_dir $1 $2

复制代码
发表于 2006-12-15 03:28:45 | 显示全部楼层
some simply way could be
  1. find . -type f -exec grep -n "whatever" {} \;
  2. find . -type f -print0 | xargs -0 grep -n "whatever"
复制代码
回复 支持 反对

使用道具 举报

发表于 2006-12-15 13:25:55 | 显示全部楼层
呵呵,高手就是高手,写的简单明了!!!!!!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表