在bash中,我希望返回包含不区分大小写的字符串"document.cookie" | "setcookie"
的每个.php|.html|.js
类型文件的文件名(以及文件的路径
我该怎么做呢?
发布于 2011-05-27 22:03:22
egrep -ir --include=*.{php,html,js} "(document.cookie|setcookie)" .
r
标志表示递归搜索(搜索子目录)。i
标志表示不区分大小写。
如果您只想要文件名,请添加l
(小写L
)标志:
egrep -lir --include=*.{php,html,js} "(document.cookie|setcookie)" .
发布于 2011-05-27 21:57:56
试试像grep -r -n -i --include="*.html *.php *.js" searchstrinhere .
这样的东西
-i
让它变得毫无意义
末尾的.
表示您希望从当前目录开始,这可以替换为任何目录。
-r
的意思是递归地沿着目录树执行此操作
-n
打印匹配的行号。
--include
允许您添加文件名、扩展名。接受通配符
有关更多信息,请参阅:http://www.gnu.org/software/grep/
发布于 2011-05-27 21:58:47
对字符串执行find
和grep
:
这将在正则表达式'(document\.cookie|setcookie)'
的/starting/path和grep中找到您的3种类型的所有文件。为了可读性,用反斜杠将代码分成两行。
find /starting/path -type f -name "*.php" -o -name "*.html" -o -name "*.js" | \
xargs egrep -i '(document\.cookie|setcookie)'
https://stackoverflow.com/questions/6153152
复制相似问题