Linux查找含有某字符串的所有文件-逆风草-51CTO博客 http://blog.51cto.com/151wqooo/1162118
如果你想在当前目录下 查找"hello,world!"字符串,可以这样:
grep -rn "hello,world!" *
* : 表示当前目录所有文件,也可以是某个文件名
-r 是递归查找
-n 是显示行号
-R 查找所有文件包含子目录
-i 忽略大小写
下面是一些有意思的命令行参数:
grep -i pattern files :不区分大小写地搜索。默认情况区分大小写,
grep -l pattern files :只列出匹配的文件名,
grep -L pattern files :列出不匹配的文件名,
grep -w pattern files :只匹配整个单词,而不是字符串的一部分(如匹配‘magic’,而不是‘magical’),
grep -C number pattern files :匹配的上下文分别显示[number]行,
grep pattern1 | pattern2 files :显示匹配 pattern1 或 pattern2 的行,
grep pattern1 files | grep pattern2 :显示既匹配 pattern1 又匹配 pattern2 的行。
这里还有些用于搜索的特殊符号:
< 和 > 分别标注单词的开始与结尾。
例如:
grep man * 会匹配 ‘Batman’、‘manic’、‘man’等,
grep '<man' * 匹配‘manic’和‘man’,但不是‘Batman’,
grep '<man>' 只匹配‘man’,而不是‘Batman’或‘manic’等其他的字符串。
'^':指匹配的字符串在行首,
'$':指匹配的字符串在行尾,
[root@d1 studygolang]# cat log/panic.log can't find /config/env.ini load config file error: open /home/ctGO/studygolang/config/env.ini: no such file or directory get mysql config error: section 'mysql' not found 2018/08/16 16:07:35 config parse redis section error: section 'redis' not found 2018/08/16 16:07:35 载入sego词典 /home/ctGO/studygolang/data/programming.txt 2018/08/16 16:07:35 载入sego词典 /home/ctGO/studygolang/data/dictionary.txt 2018/08/16 16:07:35 listen tcp :8088: bind: address already in use [root@d1 studygolang]# grep -rn "8088" 匹配到二进制文件 core.6411 template/projects/detail.html:126:.project .attrs a {font-weight: normal; color: #778088; text-decoration: none;} 匹配到二进制文件 .git/objects/pack/pack-ca0e13a216aed05da56d9895643b387effaff8c4.pack myTest/a:7:tcp 0 0 0.0.0.0:8088 0.0.0.0:* LISTEN 匹配到二进制文件 bin/studygolang 匹配到二进制文件 bin/indexer 匹配到二进制文件 bin/crawler 匹配到二进制文件 bin/migrator start-docker.sh:49:docker run -d --name studygolang-web -v `pwd`:/studygolang -p 8090:8088 --link mysqlDB:db.localhost $STUDYGOLANG_IMG ./docker-entrypoint.sh README.md:131:在浏览器中输入:http://127.0.0.1:8088 src/server/studygolang/main.go:96: global.App.Port = ConfigFile.MustValue("listen", "port", "8088") src/vendor/github.com/mattn/go-sqlite3/code/sqlite3-binding.c:155356: {8088, 150, 8}, {8104, 150, 8}, {8120, 150, 2}, src/vendor/github.com/mattn/go-sqlite3/code/sqlite3-binding.c:185020: {8088, 150, 8}, {8104, 150, 8}, {8120, 150, 2}, src/vendor/golang.org/x/text/language/tables.go:1219: 0x5886, 0x6081, 0x687b, 0x7084, 0x7889, 0x8088, 0x8883, 0x908b, src/vendor/golang.org/x/text/encoding/japanese/tables.go:11556: 4962: 0x8088, src/vendor/golang.org/x/text/encoding/japanese/tables.go:18874: 28088 - 19968: jis0208<<14 | 0x3D<<7 | 0x20, src/vendor/golang.org/x/text/encoding/korean/tables.go:7863: 8088: 0xCE25, src/vendor/golang.org/x/text/encoding/korean/tables.go:25755: 48088 - 44032: 0x92DA, src/vendor/golang.org/x/text/encoding/simplifiedchinese/tables.go:11373: 12544: 0x8088, src/vendor/golang.org/x/text/encoding/simplifiedchinese/tables.go:16912: 18088: 0x9101, src/vendor/golang.org/x/text/encoding/simplifiedchinese/tables.go:30576: 28088 - 11905: 0xBAD4, src/vendor/golang.org/x/text/encoding/simplifiedchinese/tables.go:40576: 38088 - 11905: 0xEEE6, src/vendor/golang.org/x/text/encoding/traditionalchinese/tables.go:6948: 8088: 0x00006591, src/vendor/golang.org/x/text/encoding/traditionalchinese/tables.go:16905: 18088: 0x00007042, src/vendor/golang.org/x/text/encoding/traditionalchinese/tables.go:19408: 148088 - 131105: 0xFB78, src/vendor/golang.org/x/text/encoding/traditionalchinese/tables.go:27276: 28088 - 11904: 0xB255, src/vendor/golang.org/x/text/collate/tables.go:10318: 0x055c: 0x00372e88, 0x055d: 0x40372e20, 0x055e: 0x00348088, 0x055f: 0x40348020, src/vendor/golang.org/x/text/collate/tables.go:10330: 0x0590: 0x00388088, 0x0591: 0x00388288, 0x0592: 0x00388488, 0x0593: 0x00388688, src/vendor/golang.org/x/text/collate/tables.go:11001: 0x10f8: 0x00380488, 0x10f9: 0x00380888, 0x10fa: 0x00380c88, 0x10fb: 0x00381088, src/vendor/golang.org/x/text/collate/tables.go:12717: 0x2b64: 0x00378088, 0x2b65: 0x00378288, 0x2b66: 0x00378488, 0x2b67: 0x00378688, src/vendor/golang.org/x/text/collate/tables.go:13736: 0x3ae8: 0xe0000f4d, 0x3ae9: 0xe0000f4a, 0x3aea: 0x002d8088, src/vendor/golang.org/x/text/collate/tables.go:14401: 0x4624: 0x00094a83, 0x4625: 0x0027e283, 0x4626: 0x00280883, src/vendor/golang.org/x/text/collate/tables.go:15257: 0x5520: 0x40808220, 0x5521: 0x40808420, 0x5522: 0x40808620, 0x5523: 0x40808820, src/vendor/golang.org/x/text/collate/tables.go:17984: 0x8088: 0x002d6888, 0x8089: 0x002d9a88, 0x808a: 0x002dcc88, 0x808b: 0x002dfe88, src/vendor/golang.org/x/text/collate/tables.go:20588: 0xa75c: 0x00372e88, 0xa75d: 0x40372e20, 0xa75e: 0x00348088, 0xa75f: 0x40348020, src/vendor/golang.org/x/text/collate/tables.go:30757: 0x164b8: 0x00380488, 0x164b9: 0x00380888, 0x164ba: 0x00380c88, 0x164bb: 0x00381088, src/vendor/golang.org/x/text/collate/tables.go:32628: 0x18088: 0xf000040a, 0x18089: 0xf0000404, 0x1808a: 0xf0000a0a, 0x1808b: 0xf000040a, src/vendor/golang.org/x/text/collate/tables.go:37606: 0x1ca18: 0x6c121a20, 0x1ca19: 0x6cc50c20, 0x1ca1a: 0x6d271420, 0x1ca1b: 0x6c808820, src/vendor/golang.org/x/text/collate/tables.go:40714: 0x1f81c: 0x6c948c20, 0x1f81d: 0x6c7ff820, 0x1f81e: 0x6c808820, 0x1f81f: 0x6c7ff020, src/vendor/golang.org/x/text/collate/tables.go:60519: 0x3529c: 0x6d808620, 0x3529d: 0x6d808820, 0x3529e: 0x6d808a20, 0x3529f: 0x6d808c20, src/vendor/golang.org/x/text/collate/tables.go:63297: 0x37b78: 0x6c808420, 0x37b79: 0x6c808620, 0x37b7a: 0x6c808820, 0x37b7b: 0x6c808a20, src/vendor/golang.org/x/text/collate/tables.go:63642: 0x38088: 0x6db07420, 0x38089: 0x6db07620, 0x3808a: 0x6dd00c20, 0x3808b: 0x6e2b4020, src/vendor/golang.org/x/collate/tables.go:10318: 0x055c: 0x00372e88, 0x055d: 0x40372e20, 0x055e: 0x00348088, 0x055f: 0x40348020, src/vendor/golang.org/x/collate/tables.go:10330: 0x0590: 0x00388088, 0x0591: 0x00388288, 0x0592: 0x00388488, 0x0593: 0x00388688, src/vendor/golang.org/x/collate/tables.go:11001: 0x10f8: 0x00380488, 0x10f9: 0x00380888, 0x10fa: 0x00380c88, 0x10fb: 0x00381088, src/vendor/golang.org/x/collate/tables.go:12717: 0x2b64: 0x00378088, 0x2b65: 0x00378288, 0x2b66: 0x00378488, 0x2b67: 0x00378688, src/vendor/golang.org/x/collate/tables.go:13736: 0x3ae8: 0xe0000f4d, 0x3ae9: 0xe0000f4a, 0x3aea: 0x002d8088, src/vendor/golang.org/x/collate/tables.go:14401: 0x4624: 0x00094a83, 0x4625: 0x0027e283, 0x4626: 0x00280883, src/vendor/golang.org/x/collate/tables.go:15257: 0x5520: 0x40808220, 0x5521: 0x40808420, 0x5522: 0x40808620, 0x5523: 0x40808820, src/vendor/golang.org/x/collate/tables.go:17984: 0x8088: 0x002d6888, 0x8089: 0x002d9a88, 0x808a: 0x002dcc88, 0x808b: 0x002dfe88, src/vendor/golang.org/x/collate/tables.go:20588: 0xa75c: 0x00372e88, 0xa75d: 0x40372e20, 0xa75e: 0x00348088, 0xa75f: 0x40348020, src/vendor/golang.org/x/collate/tables.go:30757: 0x164b8: 0x00380488, 0x164b9: 0x00380888, 0x164ba: 0x00380c88, 0x164bb: 0x00381088, src/vendor/golang.org/x/collate/tables.go:32628: 0x18088: 0xf000040a, 0x18089: 0xf0000404, 0x1808a: 0xf0000a0a, 0x1808b: 0xf000040a, src/vendor/golang.org/x/collate/tables.go:37606: 0x1ca18: 0x6c121a20, 0x1ca19: 0x6cc50c20, 0x1ca1a: 0x6d271420, 0x1ca1b: 0x6c808820, src/vendor/golang.org/x/collate/tables.go:40714: 0x1f81c: 0x6c948c20, 0x1f81d: 0x6c7ff820, 0x1f81e: 0x6c808820, 0x1f81f: 0x6c7ff020, src/vendor/golang.org/x/collate/tables.go:60519: 0x3529c: 0x6d808620, 0x3529d: 0x6d808820, 0x3529e: 0x6d808a20, 0x3529f: 0x6d808c20, src/vendor/golang.org/x/collate/tables.go:63297: 0x37b78: 0x6c808420, 0x37b79: 0x6c808620, 0x37b7a: 0x6c808820, 0x37b7b: 0x6c808a20, src/vendor/golang.org/x/collate/tables.go:63642: 0x38088: 0x6db07420, 0x38089: 0x6db07620, 0x3808a: 0x6dd00c20, 0x3808b: 0x6e2b4020, src/vendor/golang.org/x/encoding/japanese/tables.go:11556: 4962: 0x8088, src/vendor/golang.org/x/encoding/japanese/tables.go:18874: 28088 - 19968: jis0208<<14 | 0x3D<<7 | 0x20, src/vendor/golang.org/x/encoding/korean/tables.go:7863: 8088: 0xCE25, src/vendor/golang.org/x/encoding/korean/tables.go:25755: 48088 - 44032: 0x92DA, src/vendor/golang.org/x/encoding/simplifiedchinese/tables.go:11373: 12544: 0x8088, src/vendor/golang.org/x/encoding/simplifiedchinese/tables.go:16912: 18088: 0x9101, src/vendor/golang.org/x/encoding/simplifiedchinese/tables.go:30576: 28088 - 11905: 0xBAD4, src/vendor/golang.org/x/encoding/simplifiedchinese/tables.go:40576: 38088 - 11905: 0xEEE6, src/vendor/golang.org/x/encoding/traditionalchinese/tables.go:6948: 8088: 0x00006591, src/vendor/golang.org/x/encoding/traditionalchinese/tables.go:16905: 18088: 0x00007042, src/vendor/golang.org/x/encoding/traditionalchinese/tables.go:19408: 148088 - 131105: 0xFB78, src/vendor/golang.org/x/encoding/traditionalchinese/tables.go:27276: 28088 - 11904: 0xB255, src/vendor/golang.org/x/search/tables.go:2727: 0x055c: 0x00372e88, 0x055d: 0x40372e20, 0x055e: 0x00348088, 0x055f: 0x40348020, src/vendor/golang.org/x/search/tables.go:2739: 0x0590: 0x00388088, 0x0591: 0x00388288, 0x0592: 0x00388488, 0x0593: 0x00388688, src/vendor/golang.org/x/search/tables.go:3410: 0x10f8: 0x00380488, 0x10f9: 0x00380888, 0x10fa: 0x00380c88, 0x10fb: 0x00381088, src/vendor/golang.org/x/search/tables.go:5126: 0x2b64: 0x00378088, 0x2b65: 0x00378288, 0x2b66: 0x00378488, 0x2b67: 0x00378688, src/vendor/golang.org/x/search/tables.go:6145: 0x3ae8: 0xe0000f4d, 0x3ae9: 0xe0000f4a, 0x3aea: 0x002d8088, src/vendor/golang.org/x/search/tables.go:6810: 0x4624: 0x00094a83, 0x4625: 0x0027e283, 0x4626: 0x00280883, src/vendor/golang.org/x/search/tables.go:7666: 0x5520: 0x40808220, 0x5521: 0x40808420, 0x5522: 0x40808620, 0x5523: 0x40808820, src/vendor/golang.org/x/search/tables.go:10396: 0x8088: 0xe0000d87, 0x8089: 0xe0000d84, 0x808a: 0xe0000d81, 0x808b: 0xe0000d7e, log/panic.log:7:2018/08/16 16:07:35 listen tcp :8088: bind: address already in use 匹配到二进制文件 core.6200 Dockerfile.web:9:# docker run -d --name studygolang-web -v `pwd`:/studyglang -p 8090:8088 --link mysqlDB:db.localhost studygolang ./docker-entrypoint.sh config/env.sample.iniABK:22:port = 8088 [root@d1 studygolang]#
grep -rn "192.168.2.125" /
查找整个系统