在特定文件中查找内容(find + grep)
来源:互联网 发布:js时间选择插件 编辑:程序博客网 时间:2024/05/01 02:35
在指定类型文件中查找特定内容,我们在阅读代码中经常需要用到这样的操作,比较简单的如下操作
在当前目录及子目录中的所有java文件查找完全匹配的onCreate字符串:
$ find . -name "*\.java" | xargs grep -sw onCreate
在阅读Android-4.4.2 的源码时发现了Google这样的写法感觉很好,直接写在脚本中,然后每次启动的时候去执行这个脚本我们就可以使用这些方法了。借鉴此方法我们可以写很多这样的方法,每次启动的时候执行以下,这样就方便我们使用了。
function jgrep()
{
find . -name .repo -prune -o -name .git -prune -o -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
}
function cgrep()
{
find . -name .repo -prune -o -name .git -prune -o -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' \) -print0 | xargs -0 grep --color -n "$@"
}
function resgrep()
{
for dir in `find . -name .repo -prune -o -name .git -prune -o -name res -type d`; do find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"; done;
}
function mangrep()
{
find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
}
function sepgrep()
{
find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d -print0 | xargs -0 grep --color -n -r --exclude-dir=\.git "$@"
}
0 0
- 在特定文件中查找内容(find + grep)
- 文件内容查找 find+grep
- 文件内容查找 find+grep
- 在特定文件中查找内容
- 在文件中查找特定的字符串方法 grep命令
- 利用find和grep组合查找特定文件下的内容
- Linux 文件、内容查找(递归) ,grep ,find
- 用find & grep查找文件内容
- Linux 文件、内容查找(递归) ,grep ,find
- linux下查找文件内容!find+grep
- linux下查找文件内容!find+grep
- Linux 文件、内容查找(递归) ,grep ,find
- Linux 文件、内容查找(递归) ,grep ,find
- 使用grep find查找文件内容
- Linux 文件、内容查找(递归) ,grep ,find
- grep 查找文件中内容
- linux中find查找指定时间段的文件并grep查找内容
- linux里grep 查找文件中内容
- 判断一个字符串中是否包含另一个字符串
- 从100PV到1亿级PV网站架构演变
- 64位Win7 服务器运行失败
- robotium 方法
- 浅谈word、chm、PDF与BizHelp的区别
- 在特定文件中查找内容(find + grep)
- 开始菜单右键被禁用之完美解决
- Boost库,linux pthread库的线程互斥锁和条件变量
- Windows 8系统如何开启与禁用管理员账户方法
- Mysql在大型网站的应用架构演变
- 一个简单的返回顶部jQuery代码
- jforum初学添加页面流程
- C中的预编译宏详解
- 手机淘宝构架演化实践