ag是什么
ag是类似ack,grep的linux端搜索工具。
ag的优势
它比ack还要快 (和grep不在一个数量级上)
它会忽略.gitignore和.hgignore中的匹配文件
如果有你想忽略的文件,你需要将(congh .min.js cough*)加入到.ignore文件中
它的命令名称更短:
ag为什么这么快
- Ag使用Pthread来利用多个CPU内核并并行搜索文件。
- 使用mmap()ed 文件而不是读入缓冲区。
- 文字字符串搜索使用Boyer-Moore strstr。
- 正则表达式搜索使用PCRE的JIT编译器(如果Ag是使用PCRE> = 8.21构建的)。
- Ag pcre_study()在对每个文件执行相同的正则表达式之前调用。
- fnmatch()非正则表达式模式不是调用忽略文件中的每个模式,而是将其加载到数组中并进行二进制搜索。
在线安装
Ubuntu >= 13.10 (Saucy) or Debian >= 8 (Jessie)
apt-get install silversearcher-ag
CentOS
yum install the_silver_searcher
离线安装
源码地址:https://github.com/ggreer/the_silver_searcher/releases
下载解压到安装目录下
进入源码目录下运行
sh build.sh
提示
[root@localhost the_silver_searcher-2.2.0]# sh build.sh
./autogen.sh:行18: aclocal: 未找到命令
说明缺少automake工具,直接使用yum指令进行安装即可:
yum -y install automake
**时间受限,后续研究如何离线安装automake **
提示
[root@localhost the_silver_searcher-2.2.0]# sh build.sh
configure.ac:11: installing './compile'
configure.ac:22: installing './config.guess'
configure.ac:22: installing './config.sub'
configure.ac:8: installing './install-sh'
configure.ac:8: installing './missing'
Makefile.am: installing './depcomp'
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/root/the_silver_searcher-2.2.0':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
提示缺少C语言的环境
执行以下命令
yum -y install gcc
**时间受限,后续研究如何离线安装gcc **
又又又报错
---------略去成功部分------------------
checking pkg-config is at least version 0.9.0... yes
checking for PCRE... no
configure: error: Package requirements (libpcre) were not met:
No package 'libpcre' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables PCRE_CFLAGS
and PCRE_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
发现缺少PCRE库(在linux下需要对正则表达式的验证,使用的验证工具是pcretest,这个工具集成在pcre库中)
- 首先去官网下载压缩包文件,
https://www.pcre.org/
下载这个
ftp://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz - 解压缩后进入
cd pcre-8.44
./configure --enable-utf8
又又又又又报错
configure: error: Invalid C++ compiler or C++ compiler flags
提示没有C++库
yum install -y gcc-c++
**时间受限,后续研究如何离线安装gcc **
- 执行make
又又又又又又报错
It also requires GNU Autoconf, GNU m4 and Perl in order to run:
还要装三个,放弃,有空再装。
方案:最后解决方案
1、配置本地yum源
2、更换配置源地址
参考博客https://blog.csdn.net/qq_27385759/article/details/88836054