{"id":90572,"date":"2024-03-08T02:19:12","date_gmt":"2024-03-07T18:19:12","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=90572"},"modified":"2024-03-08T02:19:12","modified_gmt":"2024-03-07T18:19:12","slug":"grep-find-file","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/grep-find-file.html","title":{"rendered":"\u4f7f\u7528 grep \u67e5\u627e\u6240\u6709\u5305\u542b\u6307\u5b9a\u6587\u672c\u7684\u6587\u4ef6"},"content":{"rendered":"
<\/p>\n
\u76ee\u6807\uff1a<\/strong>\u672c\u6587\u63d0\u4f9b\u4e00\u4e9b\u5173\u4e8e\u5982\u4f55\u641c\u7d22\u51fa\u6307\u5b9a\u76ee\u5f55\u6216\u6574\u4e2a\u6587\u4ef6\u7cfb\u7edf\u4e2d\u90a3\u4e9b\u5305\u542b\u6307\u5b9a\u5355\u8bcd\u6216\u5b57\u7b26\u4e32\u7684\u6587\u4ef6\u3002<\/p>\n \u96be\u5ea6\uff1a<\/strong>\u5bb9\u6613<\/p>\n \u7ea6\u5b9a\uff1a<\/strong><\/p>\n \u7b2c\u4e00\u4e2a\u4f8b\u5b50\u8ba9\u6211\u4eec\u6765\u641c\u7d22 \/etc\/<\/span> \u76ee\u5f55\u4e0b\u6240\u6709\u5305\u542b stretch<\/span> \u5b57\u7b26\u4e32\u7684\u6587\u4ef6\uff0c\u4f46\u4e0d\u53bb\u641c\u7d22\u5176\u4e2d\u7684\u5b50\u76ee\u5f55:<\/p>\n grep<\/span> \u7684 -s<\/span> \u9009\u9879\u4f1a\u5728\u53d1\u73b0\u4e0d\u5b58\u5728\u6216\u8005\u4e0d\u80fd\u8bfb\u53d6\u7684\u6587\u4ef6\u65f6\u9690\u85cf\u62a5\u9519\u4fe1\u606f\u3002\u7ed3\u679c\u663e\u793a\u9664\u4e86\u6587\u4ef6\u540d\u4e4b\u5916\uff0c\u8fd8\u6709\u5305\u542b\u8bf7\u6c42\u5b57\u7b26\u4e32\u7684\u884c\u4e5f\u88ab\u4e00\u8d77\u8f93\u51fa\u4e86\u3002<\/p>\n \u4e0a\u9762\u6848\u4f8b\u4e2d\u5ffd\u7565\u4e86\u6240\u6709\u7684\u5b50\u76ee\u5f55\u3002\u6240\u8c13\u9012\u5f52\u641c\u7d22\u5c31\u662f\u6307\u540c\u65f6\u641c\u7d22\u6240\u6709\u7684\u5b50\u76ee\u5f55\u3002<\/p>\n \u4e0b\u9762\u7684\u547d\u4ee4\u4f1a\u5728 \/etc\/<\/span> \u53ca\u5176\u5b50\u76ee\u5f55\u4e2d\u641c\u7d22\u5305\u542b stretch<\/span> \u5b57\u7b26\u4e32\u7684\u6587\u4ef6\uff1a<\/p>\n \u4e0a\u9762 grep<\/span> \u547d\u4ee4\u7684\u6848\u4f8b\u4e2d\u5217\u51fa\u7684\u662f\u6240\u6709\u5305\u542b\u5b57\u7b26\u4e32 stretch<\/span> \u7684\u6587\u4ef6\u3002\u4e5f\u5c31\u662f\u8bf4\u5305\u542b stretches<\/span> \uff0c stretched<\/span> \u7b49\u5185\u5bb9\u7684\u884c\u4e5f\u4f1a\u88ab\u663e\u793a\u3002 \u4f7f\u7528 grep<\/span> \u7684 -w<\/span> \u9009\u9879\u4f1a\u53ea\u663e\u793a\u5305\u542b\u7279\u5b9a\u5355\u8bcd\u7684\u884c\uff1a<\/p>\n \u4e0a\u9762\u7684\u547d\u4ee4\u90fd\u4f1a\u4ea7\u751f\u591a\u4f59\u7684\u8f93\u51fa\u3002\u4e0b\u4e00\u4e2a\u6848\u4f8b\u5219\u4f1a\u9012\u5f52\u5730\u641c\u7d22 etc<\/span> \u76ee\u5f55\u4e2d\u5305\u542b stretch<\/span> \u7684\u6587\u4ef6\u5e76\u53ea\u8f93\u51fa\u6587\u4ef6\u540d\uff1a<\/p>\n \u9ed8\u8ba4\u60c5\u51b5\u4e0b\u641c\u7d22\u662f\u5927\u5c0f\u5199\u654f\u611f\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4\u5f53\u641c\u7d22\u5b57\u7b26\u4e32 stretch<\/span> \u65f6\u53ea\u4f1a\u5305\u542b\u5927\u5c0f\u5199\u4e00\u81f4\u5185\u5bb9\u7684\u6587\u4ef6\u3002<\/p>\n \u901a\u8fc7\u4f7f\u7528 grep<\/span> \u7684 -i<\/span> \u9009\u9879\uff0cgrep<\/span> \u547d\u4ee4\u8fd8\u4f1a\u5217\u51fa\u6240\u6709\u5305\u542b Stretch<\/span> \uff0c STRETCH<\/span> \uff0c StReTcH<\/span> \u7b49\u5185\u5bb9\u7684\u6587\u4ef6\uff0c\u4e5f\u5c31\u662f\u8bf4\u8fdb\u884c\u7684\u662f\u5927\u5c0f\u5199\u4e0d\u654f\u611f\u7684\u641c\u7d22\u3002<\/p>\n grep<\/span> \u547d\u4ee4\u4e5f\u53ef\u4ee5\u53ea\u5728\u6307\u5b9a\u6587\u4ef6\u4e2d\u8fdb\u884c\u641c\u7d22\u3002\u6bd4\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u53ea\u5728\u914d\u7f6e\u6587\u4ef6\uff08\u6269\u5c55\u540d\u4e3a.conf<\/span>\uff09\u4e2d\u641c\u7d22\u6307\u5b9a\u7684\u6587\u672c\/\u5b57\u7b26\u4e32\u3002 \u4e0b\u9762\u8fd9\u4e2a\u4f8b\u5b50\u5c31\u4f1a\u5728 \/etc<\/span> \u76ee\u5f55\u4e2d\u641c\u7d22\u5e26\u5b57\u7b26\u4e32 bash<\/span> \u4e14\u6240\u6709\u6269\u5c55\u540d\u4e3a .conf<\/span> \u7684\u6587\u4ef6\uff1a<\/p>\n \u7c7b\u4f3c\u7684\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528 --exclude<\/span> \u6765\u6392\u9664\u7279\u5b9a\u7684\u6587\u4ef6\uff1a<\/p>\n \u8ddf\u6587\u4ef6\u4e00\u6837\uff0cgrep<\/span> \u4e5f\u80fd\u5728\u641c\u7d22\u65f6\u6392\u9664\u6307\u5b9a\u76ee\u5f55\u3002 \u4f7f\u7528 --exclude-dir<\/span> \u9009\u9879\u5c31\u884c\u3002<\/p>\n \u4e0b\u9762\u8fd9\u4e2a\u4f8b\u5b50\u4f1a\u641c\u7d22 \/etc<\/span> \u76ee\u5f55\u4e2d\u641c\u6709\u5305\u542b\u5b57\u7b26\u4e32 stretch<\/span> \u7684\u6587\u4ef6\uff0c\u4f46\u4e0d\u5305\u62ec \/etc\/grub.d<\/span> \u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\uff1a<\/p>\n -n<\/span> \u9009\u9879\u8fd8\u4f1a\u663e\u793a\u6307\u5b9a\u5b57\u7b26\u4e32\u6240\u5728\u884c\u7684\u884c\u53f7:<\/p>\n \u6700\u540e\u8fd9\u4e2a\u4f8b\u5b50\u4f7f\u7528 -v<\/span> \u6765\u5217\u51fa\u6240\u6709\u4e0d<\/strong>\u5305\u542b\u6307\u5b9a\u5b57\u7b26\u4e32\u7684\u6587\u4ef6\u3002<\/p>\n \u4f8b\u5982\u4e0b\u9762\u547d\u4ee4\u4f1a\u641c\u7d22 \/etc<\/span> \u76ee\u5f55\u4e2d\u4e0d\u5305\u542b stretch<\/span> \u7684\u6240\u6709\u6587\u4ef6\uff1a<\/p>\n via: https:\/\/linuxconfig.org\/how-to-find-all-files-with-a-specific-text-using-linux-shell<\/a><\/p>\n \u4f5c\u8005\uff1aLubos Rendek<\/a>[1]<\/span> \u8bd1\u8005\uff1alujun9972<\/a>[2]<\/span> \u6821\u5bf9\uff1awxy<\/a>[3]<\/span><\/p>\n \u672c\u6587\u7531 LCTT<\/a>[4]<\/span> \u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd<\/a>[5]<\/span> \u8363\u8a89\u63a8\u51fa<\/p>\n \u539f\u6587\u6765\u81ea\uff1ahttps:\/\/linux.cn\/article-9149-1.html<\/a><\/p>\n\n
# grep -s stretch \/etc\/*\r\n\/etc\/os-release:PRETTY_NAME=\"Debian GNU\/Linux 9 (stretch)\"\r\n\/etc\/os-release:VERSION=\"9 (stretch)\"\r\n<\/pre>\n
# grep -R stretch \/etc\/*\r\n\/etc\/apt\/sources.list:# deb cdrom:[Debian GNU\/Linux testing _Stretch_ - Official Snapshot amd64 NETINST Binary-1 20170109-05:56]\/ stretch main\r\n\/etc\/apt\/sources.list:#deb cdrom:[Debian GNU\/Linux testing _Stretch_ - Official Snapshot amd64 NETINST Binary-1 20170109-05:56]\/ stretch main\r\n\/etc\/apt\/sources.list:deb http:\/\/ftp.au.debian.org\/debian\/ stretch main\r\n\/etc\/apt\/sources.list:deb-src http:\/\/ftp.au.debian.org\/debian\/ stretch main\r\n\/etc\/apt\/sources.list:deb http:\/\/security.debian.org\/debian-security stretch\/updates main\r\n\/etc\/apt\/sources.list:deb-src http:\/\/security.debian.org\/debian-security stretch\/updates main\r\n\/etc\/dictionaries-common\/words:backstretch\r\n\/etc\/dictionaries-common\/words:backstretch's\r\n\/etc\/dictionaries-common\/words:backstretches\r\n\/etc\/dictionaries-common\/words:homestretch\r\n\/etc\/dictionaries-common\/words:homestretch's\r\n\/etc\/dictionaries-common\/words:homestretches\r\n\/etc\/dictionaries-common\/words:outstretch\r\n\/etc\/dictionaries-common\/words:outstretched\r\n\/etc\/dictionaries-common\/words:outstretches\r\n\/etc\/dictionaries-common\/words:outstretching\r\n\/etc\/dictionaries-common\/words:stretch\r\n\/etc\/dictionaries-common\/words:stretch's\r\n\/etc\/dictionaries-common\/words:stretched\r\n\/etc\/dictionaries-common\/words:stretcher\r\n\/etc\/dictionaries-common\/words:stretcher's\r\n\/etc\/dictionaries-common\/words:stretchers\r\n\/etc\/dictionaries-common\/words:stretches\r\n\/etc\/dictionaries-common\/words:stretchier\r\n\/etc\/dictionaries-common\/words:stretchiest\r\n\/etc\/dictionaries-common\/words:stretching\r\n\/etc\/dictionaries-common\/words:stretchy\r\n\/etc\/grub.d\/00_header:background_image -m stretch `make_system_path_relative_to_its_root \"$GRUB_BACKGROUND\"`\r\n\/etc\/os-release:PRETTY_NAME=\"Debian GNU\/Linux 9 (stretch)\"\r\n\/etc\/os-release:VERSION=\"9 (stretch)\"\r\n<\/pre>\n
# grep -Rw stretch \/etc\/*\r\n\/etc\/apt\/sources.list:# deb cdrom:[Debian GNU\/Linux testing _Stretch_ - Official Snapshot amd64 NETINST Binary-1 20170109-05:56]\/ stretch main\r\n\/etc\/apt\/sources.list:#deb cdrom:[Debian GNU\/Linux testing _Stretch_ - Official Snapshot amd64 NETINST Binary-1 20170109-05:56]\/ stretch main\r\n\/etc\/apt\/sources.list:deb http:\/\/ftp.au.debian.org\/debian\/ stretch main\r\n\/etc\/apt\/sources.list:deb-src http:\/\/ftp.au.debian.org\/debian\/ stretch main\r\n\/etc\/apt\/sources.list:deb http:\/\/security.debian.org\/debian-security stretch\/updates main\r\n\/etc\/apt\/sources.list:deb-src http:\/\/security.debian.org\/debian-security stretch\/updates main\r\n\/etc\/dictionaries-common\/words:stretch\r\n\/etc\/dictionaries-common\/words:stretch's\r\n\/etc\/grub.d\/00_header:background_image -m stretch `make_system_path_relative_to_its_root \"$GRUB_BACKGROUND\"`\r\n\/etc\/os-release:PRETTY_NAME=\"Debian GNU\/Linux 9 (stretch)\"\r\n\/etc\/os-release:VERSION=\"9 (stretch)\"\r\n<\/pre>\n
# grep -Rl stretch \/etc\/*\r\n\/etc\/apt\/sources.list\r\n\/etc\/dictionaries-common\/words\r\n\/etc\/grub.d\/00_header\r\n\/etc\/os-release\r\n<\/pre>\n
# grep -Ril stretch \/etc\/*\r\n\/etc\/apt\/sources.list\r\n\/etc\/dictionaries-common\/default.hash\r\n\/etc\/dictionaries-common\/words\r\n\/etc\/grub.d\/00_header\r\n\/etc\/os-release\r\n<\/pre>\n
# grep -Ril bash \/etc\/*.conf\r\nOR\r\n# grep -Ril --include=\\*.conf bash \/etc\/*\r\n\/etc\/adduser.conf\r\n<\/pre>\n
# grep -Ril --exclude=\\*.conf bash \/etc\/*\r\n\/etc\/alternatives\/view\r\n\/etc\/alternatives\/vim\r\n\/etc\/alternatives\/vi\r\n\/etc\/alternatives\/vimdiff\r\n\/etc\/alternatives\/rvim\r\n\/etc\/alternatives\/ex\r\n\/etc\/alternatives\/rview\r\n\/etc\/bash.bashrc\r\n\/etc\/bash_completion.d\/grub\r\n\/etc\/cron.daily\/apt-compat\r\n\/etc\/cron.daily\/exim4-base\r\n\/etc\/dictionaries-common\/default.hash\r\n\/etc\/dictionaries-common\/words\r\n\/etc\/inputrc\r\n\/etc\/passwd\r\n\/etc\/passwd-\r\n\/etc\/profile\r\n\/etc\/shells\r\n\/etc\/skel\/.profile\r\n\/etc\/skel\/.bashrc\r\n\/etc\/skel\/.bash_logout\r\n<\/pre>\n
# grep --exclude-dir=\/etc\/grub.d -Rwl stretch \/etc\/*\r\n\/etc\/apt\/sources.list\r\n\/etc\/dictionaries-common\/words\r\n\/etc\/os-release\r\n<\/pre>\n
# grep -Rni bash \/etc\/*.conf\r\n\/etc\/adduser.conf:6:DSHELL=\/bin\/bash\r\n<\/pre>\n
# grep -Rlv stretch \/etc\/*\r\n<\/pre>\n
\n\n