首页 > 系统相关 >【grep】linux 查找某目录下包含关键字内容的文件

【grep】linux 查找某目录下包含关键字内容的文件

时间:2023-03-21 10:12:45浏览次数:51  
标签:grep PATTERNS -- lines 关键字 NUM FILE linux print

1、目的

    由于工作需要,需要查询包含某个接口的文件

 

2、方法

    基于grep查询包含某个文件的内容

-> % grep --help
Usage: grep [OPTION]... PATTERNS [FILE]...
Search for PATTERNS in each FILE.
Example: grep -i 'hello world' menu.h main.c
PATTERNS can contain multiple patterns separated by newlines.

Pattern selection and interpretation:
  -E, --extended-regexp     PATTERNS are extended regular expressions
  -F, --fixed-strings       PATTERNS are strings
  -G, --basic-regexp        PATTERNS are basic regular expressions
  -P, --perl-regexp         PATTERNS are Perl regular expressions
  -e, --regexp=PATTERNS     use PATTERNS for matching
  -f, --file=FILE           take PATTERNS from FILE
  -i, --ignore-case         ignore case distinctions
  -w, --word-regexp         match only whole words
  -x, --line-regexp         match only whole lines
  -z, --null-data           a data line ends in 0 byte, not newline

Miscellaneous:
  -s, --no-messages         suppress error messages
  -v, --invert-match        select non-matching lines
  -V, --version             display version information and exit
      --help                display this help text and exit

Output control:
  -m, --max-count=NUM       stop after NUM selected lines
  -b, --byte-offset         print the byte offset with output lines
  -n, --line-number         print line number with output lines
      --line-buffered       flush output on every line
  -H, --with-filename       print file name with output lines
  -h, --no-filename         suppress the file name prefix on output
      --label=LABEL         use LABEL as the standard input file name prefix
  -o, --only-matching       show only nonempty parts of lines that match
  -q, --quiet, --silent     suppress all normal output
      --binary-files=TYPE   assume that binary files are TYPE;
                            TYPE is 'binary', 'text', or 'without-match'
  -a, --text                equivalent to --binary-files=text
  -I                        equivalent to --binary-files=without-match
  -d, --directories=ACTION  how to handle directories;
                            ACTION is 'read', 'recurse', or 'skip'
  -D, --devices=ACTION      how to handle devices, FIFOs and sockets;
                            ACTION is 'read' or 'skip'
  -r, --recursive           like --directories=recurse
  -R, --dereference-recursive  likewise, but follow all symlinks
      --include=GLOB        search only files that match GLOB (a file pattern)
      --exclude=GLOB        skip files and directories matching GLOB
      --exclude-from=FILE   skip files matching any file pattern from FILE
      --exclude-dir=GLOB    skip directories that match GLOB
  -L, --files-without-match  print only names of FILEs with no selected lines
  -l, --files-with-matches  print only names of FILEs with selected lines
  -c, --count               print only a count of selected lines per FILE
  -T, --initial-tab         make tabs line up (if needed)
  -Z, --null                print 0 byte after FILE name

Context control:
  -B, --before-context=NUM  print NUM lines of leading context
  -A, --after-context=NUM   print NUM lines of trailing context
  -C, --context=NUM         print NUM lines of output context
  -NUM                      same as --context=NUM
      --color[=WHEN],
      --colour[=WHEN]       use markers to highlight the matching strings;
                            WHEN is 'always', 'never', or 'auto'
  -U, --binary              do not strip CR characters at EOL (MSDOS/Windows)

When FILE is '-', read standard input.  With no FILE, read '.' if
recursive, '-' otherwise.  With fewer than two FILEs, assume -h.
Exit status is 0 if any line (or file if -L) is selected, 1 otherwise;
if any error occurs and -q is not given, the exit status is 2.

Report bugs to: [email protected]
GNU grep home page: <http://www.gnu.org/software/grep/>
General help using GNU software: <https://www.gnu.org/gethelp/>

查询某个目录下

grep -r 'keyword' dirctory

查询某个文件,忽略大小写

grep -i 'hello world' menu.h main.c

 

其他可以自行探索

 

标签:grep,PATTERNS,--,lines,关键字,NUM,FILE,linux,print
From: https://www.cnblogs.com/fireblackman/p/17238923.html

相关文章

  • Linux学习第二课-Linux常用命令
    1.远程连接Linux工具:putty(https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html)、xshell(https://www.xshellcn.com/xshell.html)等​ 个人喜欢使用putty......
  • 07linux启动文件添加环境变量
    添加一个环境变量场景vi/etc/profile  在文件最后面添加(如下是go执行的路径)exportPATH=$PATH:/usr/local/go/bin添加多个,路径与路径用:隔开 ......
  • Linux操作系统之tcpdump抓包工具详解
    前言①tcpdump工具简介:tcpdump是Linux操作系统中的字符界面的数据抓包分析软件。tcpdump可以将网络中传送的数据包完全截获下来提供分析②tcpdump是一个用于截取网络分......
  • 12、static关键字
    static关键字可以修饰变量或者函数。声明局部静态变量声明类内静态数据成员/成员函数。1、声明局部静态变量voidtest(){staticinta=1;//静态局部变量i......
  • Linux启动Java程序jar包Shell脚本
    手动方式启动和终止java程序启动java程序jar:nohupjava-jarXXX.jar查看程序占用pid:ps-ef|grepXXX.jar或jpsjps是jdk提供的一个查看当前java进程的小工具,查询Lin......
  • VirtualBox 5.1.12发布支持Linux Kernel 4.10
    甲骨文(Oracle)近日宣布了VirtualBox5.1稳定版分支最新维护版本更新,带来了大量有价值的BUG修复和系统改善。VirtualBox5.1.12尤其为​​Linux​​用户新增了大量内容,除了支......
  • Linux
    Linux计算机=硬件+软件常见操作系统(软件):Linux、Windows、macOS、Android、iOS、HarmonyOSLinux系统组成:Linux系统内核:开源免费系统级应用程序使用VMware虚拟机运......
  • Linux 系统日志初学者指南
    几十年来,Linux日志记录一直由syslogd守护进程管理(注意rsyslogd是syslogd的新版本,是一个东西)。Syslogd将收集系统进程和应用程序发送到 ​​/dev/log​​ 的日志......
  • VirtualBox 5.1.12发布支持Linux Kernel 4.10
    甲骨文(Oracle)近日宣布了VirtualBox5.1稳定版分支最新维护版本更新,带来了大量有价值的BUG修复和系统改善。VirtualBox5.1.12尤其为​​Linux​​用户新增了大量内容,除了支......
  • VirtualBox 5.1.12发布支持Linux Kernel 4.10
    甲骨文(Oracle)近日宣布了VirtualBox5.1稳定版分支最新维护版本更新,带来了大量有价值的BUG修复和系统改善。VirtualBox5.1.12尤其为Linux用户新增了大量内容,除了支持即......