博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
grep 详解
阅读量:4704 次
发布时间:2019-06-10

本文共 2789 字,大约阅读时间需要 9 分钟。

grep

是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来。(global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)

常见用法

1. ps -ef | grep ****    配合 ps 命令 用的比较多。

2. grep -Ev "^#|^$" /etc/redis.conf  查看redis配置文件的不以#开头 或者是空行 的内容 

 以下就是输出的内容

protected-mode noport 6379tcp-backlog 511timeout 0tcp-keepalive 300daemonize yessupervised nopidfile /var/run/redis_6379.pidloglevel noticelogfile /var/log/redis/redis.logdatabases 16save 900 1save 300 10save 60 10000stop-writes-on-bgsave-error nordbcompression yesrdbchecksum yesdbfilename dump.rdbdir /var/lib/redisslave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100appendonly noappendfilename "appendonly.aof"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yeslua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events ""hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size -2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yes
redis.conf 配置内容

如果先嫌显示的太多,可以在后面再加 | grep -E "bind|port|tcp-backlog|daemonize|pidfile|loglevel|logfile|dir|requirepass|appendonly|appendfsync" 就会显示你要的含有关键词的内容

3. 其他方法我不常用,就先不写。

参数

  • -a 或 --text : 不要忽略二进制的数据。
  • -A<显示行数> 或 --after-context=<显示行数> : 除了显示符合范本样式的那一列之外,并显示该行之后的内容。
  • -b 或 --byte-offset : 在显示符合样式的那一行之前,标示出该行第一个字符的编号。
  • -B<显示行数> 或 --before-context=<显示行数> : 除了显示符合样式的那一行之外,并显示该行之前的内容。
  • -c 或 --count : 计算符合样式的列数。
  • -C<显示行数> 或 --context=<显示行数>或-<显示行数> : 除了显示符合样式的那一行之外,并显示该行之前后的内容。
  • -d <动作> 或 --directories=<动作> : 当指定要查找的是目录而非文件时,必须使用这项参数,否则grep指令将回报信息并停止动作。
  • -e<范本样式> 或 --regexp=<范本样式> : 指定字符串做为查找文件内容的样式。
  • -E 或 --extended-regexp : 将样式为延伸的普通表示法来使用。【就是可以匹配多个,匹配多个用 | 符号】
  • -f<规则文件> 或 --file=<规则文件> : 指定规则文件,其内容含有一个或多个规则样式,让grep查找符合规则条件的文件内容,格式为每行一个规则样式。
  • -F 或 --fixed-regexp : 将样式视为固定字符串的列表。
  • -G 或 --basic-regexp : 将样式视为普通的表示法来使用。
  • -h 或 --no-filename : 在显示符合样式的那一行之前,不标示该行所属的文件名称。
  • -H 或 --with-filename : 在显示符合样式的那一行之前,表示该行所属的文件名称。
  • -i 或 --ignore-case : 忽略字符大小写的差别。
  • -l 或 --file-with-matches : 列出文件内容符合指定的样式的文件名称。
  • -L 或 --files-without-match : 列出文件内容不符合指定的样式的文件名称。
  • -n 或 --line-number : 在显示符合样式的那一行之前,标示出该行的列数编号。
  • -q 或 --quiet或--silent : 不显示任何信息。
  • -r 或 --recursive : 此参数的效果和指定"-d recurse"参数相同。
  • -s 或 --no-messages : 不显示错误信息。
  • -v 或 --revert-match : 显示不包含匹配文本的所有行。【取相反的意思】
  • -V 或 --version : 显示版本信息。
  • -w 或 --word-regexp : 只显示全字符合的列。
  • -x --line-regexp : 只显示全列符合的列。
  • -y : 此参数的效果和指定"-i"参数相同。

 

转载于:https://www.cnblogs.com/jinxiao-pu/p/9192764.html

你可能感兴趣的文章
分布式一致性协议-2PC与3PC(二)
查看>>
SCP-bzoj-1079
查看>>
Python 实践项目 游戏
查看>>
AJAX--Jquery
查看>>
模拟新浪微博随便看看
查看>>
环境搭建
查看>>
解密EXL
查看>>
简易版cnlog
查看>>
erlang程序运行的几种方式
查看>>
堆heap和栈Stack(百科)
查看>>
html5页面实现点击复制功能
查看>>
633. 寻找重复的数
查看>>
沉淀,再出发:python中的pandas包
查看>>
Rule 12: Remove Duplicate Scripts(Chapter 12 of High performance Web Sites)
查看>>
缓存服务的更新策略有哪些?
查看>>
RMAN还原时注意set newname时文件名不要有空格
查看>>
一种链表的实现
查看>>
vue中ESlint报错
查看>>
NetCore2.0 RozarPage自动生成增删改查
查看>>
0816 1459 json & pickle ,目录导入,目录规范
查看>>