Linux 下 ag 命令的使用


一、概述

1、功能

在 Linux 系统中,ag 命令是用于文本搜索的高效工具。它具有快速、灵活的搜索功能,并支持正则表达式匹配。

2、下载

在下面是各个系统安装 ag 的命令:

sudo apt-get install silversearcher-ag
  1. MacOS:
brew install the_silver_searcher
  1. Debian/Ubuntu:
sudo apt-get install silversearcher-ag
  1. CentOS:
sudo yum install the_silver_searcher
  1. Fedora:
sudo dnf install the_silver_searcher
  1. Arch:
sudo pacman -S the_silver_searcher

二、常用参数说明

ag 目录的语法格式如下:

ag [选项] [搜索模式] [文件/目录]

下面是一些常用的参数:

  • -i:忽略大小写进行搜索;
  • -w:只匹配整个单词,而不是部分匹配;
  • -r:递归搜索指定目录下的文件;
  • -l:只列出匹配的文件名;
  • -c:统计匹配的文件数;
  • -n:显示行号。

更多参数信息,可以使用命令:ag -h 查看。

三、实例

  1. 在指定目录下查询字符串
ag pattern /path/to/directory

pattern 是要搜索的字符串,/path/to/directory 是要搜索的目录。如果省略了目录信息,则表示在当前目录及其子目录下搜索包含 pattern 的文件。

例如:

[projectsauron]:~/linux/nfs/busybox-1.29.0$ ag "alloc" ./include
include/dump.h
52:dumper_t* alloc_dumper(void) FAST_FUNC;

include/bb_e2fs_defs.h
406:	 * Performance hints.  Directory preallocation should only
407:	 * happen if the EXT2_FEATURE_COMPAT_DIR_PREALLOC flag is on.
409:	uint8_t		s_prealloc_blocks;	/* Nr of blocks to try to preallocate*/
410:	uint8_t		s_prealloc_dir_blocks;	/* Nr to
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值