文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>grep、find+exec、find+xargs 搜索源码中的字符串

grep、find+exec、find+xargs 搜索源码中的字符串

时间:2007-04-12  来源:tobeabetterman

在linux下搜索文件中的关键字,以及确定所在文件,并对find+exec、find+xargs进行效率测试

原来自己用的笨办法
cat *.c|grep 'soundcore_fops'
却没有办法知道是在哪个文件里
最简单的方法是用
grep 'soundcore_fops' *.c
或者用find
find ./ -name "*.c" -print0 |xargs -i -0 grep -n "{}"

然后对find+exec、find+xargs进行效率测试
采用findutils-4.2.30
# time find /usr/include -type f -exec grep NFS_VERSION {} +
/usr/include/rpcsvc/nfs_prot.x: version NFS_VERSION {
/usr/include/rpcsvc/nfs_prot.h:#define NFS_VERSION 2

real    0m30.801s
user    0m28.801s
sys     0m0.893s
# time find /usr/include -type f -exec grep NFS_VERSION {} \;
        version NFS_VERSION {
#define NFS_VERSION 2

real    0m57.942s
user    0m37.451s
sys     0m20.003s
# time find /usr/include -type f|xargs grep NFS_VERSION                       
/usr/include/rpcsvc/nfs_prot.x: version NFS_VERSION {
/usr/include/rpcsvc/nfs_prot.h:#define NFS_VERSION 2

real    0m31.092s
user    0m28.829s
sys     0m0.895s

似乎采用find 。。。-exec 。。。{} + 在效率上有很大的提高阿!
相关阅读 更多 +
排行榜 更多 +
奇境小镇MOD作弊菜单

奇境小镇MOD作弊菜单

角色扮演 下载
黑暗荒野2无限金币版

黑暗荒野2无限金币版

角色扮演 下载
骑战烈火之剑作弊菜单版

骑战烈火之剑作弊菜单版

角色扮演 下载