Chinaunix

标题: 在目录及子目录中的文件中查询某个字符串 [打印本页]

作者: wangsir202    时间: 2004-05-24 16:05
标题: 在目录及子目录中的文件中查询某个字符串
问题和题目一样
作者: bjgirl    时间: 2004-05-24 16:15
标题: 在目录及子目录中的文件中查询某个字符串
find,grep,awk,sed,...都可以!
作者: launch401    时间: 2004-05-24 16:29
标题: 在目录及子目录中的文件中查询某个字符串
这些命令用一定的参数应该都可以深入到子目录里面
但是如果用for循环,有没有通用的方法可以深入到子目录里面去?
作者: soopy_linux    时间: 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
作者: pxlsszf    时间: 2004-06-01 18:25
标题: 在目录及子目录中的文件中查询某个字符串
use this shell:
find . -type f -exec grep "find_string" {}  \; -print
作者: zhangweibo    时间: 2006-12-31 09:02
原帖由 pxlsszf 于 2004-6-1 18:25 发表
use this shell:
find . -type f -exec grep "find_string" {}  \; -print


linux的命令真是强大,这个比较实用,谢谢!
作者: szszszsz    时间: 2006-12-31 14:41
如果是文件里面的内容话,应该可以用grep  "字符串" -r 要目录,-r是递归下去的
作者: wudicc    时间: 2006-12-31 15:58
试过了,确实好用!
作者: IAMTOP1982    时间: 2006-12-31 16:00
grep -r 应该也可以
作者: seasee    时间: 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.
作者: lovesaka    时间: 2007-01-01 02:29
原帖由 zhangweibo 于 2006-12-31 09:02 发表


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

你知道这样一个命令要起动多少个grep进程吗最好别这么用




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2