免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 2581 | 回复: 10
打印 上一主题 下一主题

在目录及子目录中的文件中查询某个字符串 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-05-24 16:05 |只看该作者 |倒序浏览
问题和题目一样

论坛徽章:
0
2 [报告]
发表于 2004-05-24 16:15 |只看该作者

在目录及子目录中的文件中查询某个字符串

find,grep,awk,sed,...都可以!

论坛徽章:
0
3 [报告]
发表于 2004-05-24 16:29 |只看该作者

在目录及子目录中的文件中查询某个字符串

这些命令用一定的参数应该都可以深入到子目录里面
但是如果用for循环,有没有通用的方法可以深入到子目录里面去?

论坛徽章:
0
4 [报告]
发表于 2004-05-25 12:52 |只看该作者

在目录及子目录中的文件中查询某个字符串

#!/bin/csh -f

foreach i (`grep "字串" * | awk 'BEGIN {FS=":"} {print $1}'`)
     mv $i ${i}.bak
rm ${i}.bak
end
rm ${i}.bak > /dev/null 2>&1

论坛徽章:
0
5 [报告]
发表于 2004-06-01 18:25 |只看该作者

在目录及子目录中的文件中查询某个字符串

use this shell:
find . -type f -exec grep "find_string" {}  \; -print

论坛徽章:
0
6 [报告]
发表于 2006-12-31 09:02 |只看该作者
原帖由 pxlsszf 于 2004-6-1 18:25 发表
use this shell:
find . -type f -exec grep "find_string" {}  \; -print


linux的命令真是强大,这个比较实用,谢谢!

论坛徽章:
0
7 [报告]
发表于 2006-12-31 14:41 |只看该作者
如果是文件里面的内容话,应该可以用grep  "字符串" -r 要目录,-r是递归下去的

论坛徽章:
0
8 [报告]
发表于 2006-12-31 15:58 |只看该作者
试过了,确实好用!

论坛徽章:
0
9 [报告]
发表于 2006-12-31 16:00 |只看该作者
grep -r 应该也可以

论坛徽章:
0
10 [报告]
发表于 2006-12-31 20:13 |只看该作者
-d ACTION, --directories=ACTION
              If an input file is a directory, use ACTION to process  it.   By
              default,  ACTION  is read, which means that directories are read
              just as if they were ordinary files.  If ACTION is skip,  direc-
              tories  are  silently skipped.  If ACTION is recurse, grep reads
              all files under each directory, recursively; this is  equivalent
              to the -r option.



       -R, -r, --recursive
              Read all files under each directory, recursively; this is equiv-
              alent to the -d recurse option.

         --include=PATTERN
              Recurse in directories only searching file matching PATTERN.

         --exclude=PATTERN
              Recurse in directories skip file matching PATTERN.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP