优秀的编程知识分享平台

网站首页 > 技术文章 正文

linux三剑客之grep的常用用法(linux的grep命令详解)

nanyue 2024-09-10 16:12:09 技术文章 4 ℃

1 grep的常用用法

  • grep [参数]

-i 匹配忽略大小写

-c 只输出匹配的行数

-n 显示匹配的行号

-w 完全匹配

-r 递归的查询 -v 是不包含某个字串

root@wadequ-ThinkPad-L13:~# cat goinstall.sh   //源文件内容
go install github.com/ramya-rao-a/go-outline
go install github.com/acroca/go-symbols
go install github.com/mdempsky/gocode
go install github.com/rogpeppe/godef
go install github.com/zmb3/gogetdoc
go install github.com/fatih/gomodifytags
go install sourcegraph.com/sqs/goreturns
go install github.com/cweill/gotests/...
go install github.com/josharian/impl
go install github.com/haya14busa/goplay/cmd/goplay
go install github.com/uudashr/gopkgs/cmd/gopkgs
go install github.com/davidrjenni/reftools/cmd/fillstruct
go install github.com/alecthomas/gometalinter
$GOPATH/bin/gometalinter --install
go install golang.org/x/tools/cmd/godoc
go install golang.org/x/lint/golint
go install golang.org/x/tools/cmd/gorename
go install golang.org/x/tools/cmd/goimports
go install golang.org/x/tools/cmd/guru
root@wadequ-ThinkPad-L13:~# cat goinstall.sh|grep -c cweill  //显示匹配的行的个数
1
root@wadequ-ThinkPad-L13:~# grep -w alecthomas  goinstall.sh //完全匹配
go install github.com/alecthomas/gometalinter
root@wadequ-ThinkPad-L13:~# grep -n alecthomas  goinstall.sh //匹配且显示行号
13:go install github.com/alecthomas/gometalinter
oot@wadequ-ThinkPad-L13:/opt/go/velero/hack# grep -r velero ./  //递归的查询且显示文件名称
./changelog-check.sh:    echo "PR ${pr_number} is missing a changelog. Please refer https://velero.io/docs/main/code-standards/#adding-a-changelog and add a changelog."
//当我们查找日志时需要显示上面或者下面几行可以使用-C
root@wadequ-ThinkPad-L13:/var/log# tail -fn  500 boot.log |grep -C 5 Failed
         Starting senseshield...
         Starting Unbound DNS server...
         Starting containerd container runtime...
         Starting Permit User Sessions...
         Starting OpenBSD Secure Shell server...
[FAILED] Failed to start Teredo IPv6 tunneling.
See 'systemctl status miredo.service' for details.
[  OK  ] Started OpenVPN service.
[  OK  ] Started Permit User Sessions.
[  OK  ] Started Modem Manager.
         Starting GNOME Display Manager...

Tags:

最近发表
标签列表