{"id":85714,"date":"2023-12-23T22:18:31","date_gmt":"2023-12-23T14:18:31","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=85714"},"modified":"2023-12-23T22:18:31","modified_gmt":"2023-12-23T14:18:31","slug":"grep-command-instance","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/grep-command-instance.html","title":{"rendered":"grep \u547d\u4ee4\u7684 12 \u4e2a\u5b9e\u4f8b"},"content":{"rendered":"

\u4f60\u662f\u5426\u9047\u5230\u8fc7\u9700\u8981\u5728\u6587\u4ef6\u4e2d\u67e5\u627e\u4e00\u4e2a\u7279\u5b9a\u7684\u5b57\u7b26\u4e32\u6216\u8005\u6837\u5f0f\uff0c\u4f46\u662f\u4e0d\u77e5\u9053\u4ece\u54ea\u513f\u5f00\u59cb\uff1f\u90a3\u4e48,\u5c31\u8bf7grep<\/strong>\u6765\u5e2e\u4f60\u5427\u3002<\/p>\n

\"\"<\/p>\n

grep<\/strong>\u662f\u6bcf\u4e2aLinux<\/strong>\u53d1\u884c\u7248\u90fd\u9884\u88c5\u7684\u4e00\u4e2a\u5f3a\u6709\u529b\u7684\u6587\u4ef6\u6a21\u5f0f\u641c\u7d22\u5de5\u5177\u3002\u65e0\u8bba\u4f55\u79cd\u539f\u56e0\uff0c\u5982\u679c\u4f60\u7684\u7cfb\u7edf\u6ca1\u6709\u9884\u88c5\u5b83\u7684\u8bdd\uff0c\u4f60\u53ef\u4ee5\u5f88\u5bb9\u6613\u7684\u901a\u8fc7\u7cfb\u7edf\u7684\u5305\u7ba1\u7406\u5668\u6765\u5b89\u88c5\u5b83\uff08Debian\/Ubuntu<\/strong>\u7cfb\u4e2d\u7684apt-get<\/strong>\u548cRHEl\/CentOS\/Fedora<\/strong>\u7cfb\u4e2d\u7684yum<\/strong>\uff09\u3002<\/p>\n

 $ sudo apt-get install grep #Debian\/Ubuntu $ sudo yum install grep #RHEL\/CentOS\/Fedora\r\n<\/pre>\n

\u6211\u53d1\u73b0\u4f7f\u7528\u73b0\u5b9e\u4e16\u754c\u4e2d\u7684\u771f\u5b9e\u4f8b\u5b50\u8ba9\u4f60\u6295\u8eab\u5176\u4e2d\u662f\u8ba9\u4f60\u63a5\u89e6grep<\/strong>\u547d\u4ee4\u7684\u6700\u5bb9\u6613\u65b9\u5f0f\u3002<\/p>\n

1.\u641c\u7d22\u548c\u5bfb\u627e\u6587\u4ef6<\/strong><\/div>\n

\u5047\u8bbe\u4f60\u5df2\u7ecf\u5728\u4f60\u7684\u7535\u8111\u4e0a\u5b89\u88c5\u4e86\u4e00\u4e2a\u5168\u65b0\u7684Ubuntu<\/strong>\uff0c\u7136\u540e\u4f60\u6253\u7b97\u5378\u8f7dPython<\/strong>\u3002\u4f60\u6d4f\u89c8\u7f51\u9875\u5bfb\u627e\u6559\u7a0b\uff0c\u4f46\u662f\u4f60\u53d1\u73b0\u5b58\u5728\u4e24\u4e2a\u4e0d\u540c\u7248\u672c\u7684Python<\/strong>\u5728\u4f7f\u7528\uff0c\u800c\u4f60\u4e0d\u77e5\u9053\u4f60\u7684Ubuntu<\/strong>\u5b89\u88c5\u5668\u5230\u5e95\u5728\u4f60\u7684\u7cfb\u7edf\u4e2d\u5b89\u88c5\u4e86\u54ea\u4e2a\u7248\u672c\u7684Python\uff0c\u4e5f\u4e0d\u77e5\u9053\u5b83\u5b89\u88c5\u4e86\u54ea\u4e9b\u6a21\u5757\u3002\u89e3\u51b3\u8fd9\u4e2a\u70e6\u607c\u53ea\u9700\u7b80\u5355\u7684\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

 $ sudo dpkg -l | grep -i python\r\n<\/pre>\n
\u8f93\u51fa\u4f8b\u5b50<\/strong><\/span><\/div>\n
 ii python2.7 2.7.3-0ubuntu3.4 Interactive high-level object-oriented language (version 2.7)\r\n ii python2.7-minimal 2.7.3-0ubuntu3.4 Minimal subset of the Python language (version 2.7)\r\n ii python-openssl 0.12-1ubuntu2.1 Python wrapper around the OpenSSL library\r\n ii python-pam 0.4.2-12.2ubuntu4 A Python interface to the PAM library<\/pre>\n

\u9996\u5148\uff0c\u6211\u4eec\u8fd0\u884cdpkg -l<\/strong>\u5217\u51fa\u4f60\u7cfb\u7edf\u4e0a\u5b89\u88c5\u7684.deb<\/strong>\u5305\u3002\u63a5\u7740\uff0c\u6211\u4eec\u4f7f\u7528\u7ba1\u9053\u5c06\u8f93\u51fa\u7ed3\u679c\u4f20\u8f93\u7ed9\u547d\u4ee4grep -i<\/strong> python\uff0c\u8fd9\u4e00\u6b65\u53ef\u4ee5\u7b80\u5355\u89e3\u91ca\u4e3a\u628a\u7ed3\u679c\u4f20\u8f93\u7ed9grep\u7136\u540e\u8fc7\u6ee4\u51fa\u6240\u6709\u542b\u6709python\u7684\u9879\uff0c\u5e76\u8fd4\u56de\u7ed3\u679c\u3002\u2013i\u9009\u9879\u7528\u4e8e\u5ffd\u7565\u5927\u5c0f\u5199,\u56e0\u4e3a grep \u662f\u5927\u5c0f\u5199\u654f\u611f\u7684\u3002\u4f7f\u7528\u9009\u9879-i<\/strong>\u662f\u4e2a\u597d\u4e60\u60ef\uff0c\u9664\u975e\u4f60\u6253\u7b97\u8fdb\u884c\u66f4\u7ec6\u8282\u7684\u641c\u7d22\u3002<\/p>\n

2.\u641c\u7d22\u548c\u8fc7\u6ee4\u6587\u4ef6<\/strong><\/div>\n

grep\u8fd8\u53ef\u4ee5\u5728\u4e00\u4e2a\u6216\u591a\u4e2a\u6587\u4ef6\u91cc\u7528\u4e8e\u641c\u7d22\u548c\u8fc7\u6ee4\u3002\u8ba9\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u8fd9\u6837\u7684\u60c5\u666f\uff1a<\/p>\n

\u4f60\u7684Apache\u7f51\u9875\u670d\u52a1\u5668<\/strong>\u51fa\u73b0\u4e86\u95ee\u9898\uff0c\u4f60\u4e0d\u5f97\u4e0d\u4ece\u8bb8\u591a\u4e13\u4e1a\u7f51\u7ad9\u91cc\u627e\u4e00\u4e2a\u53d1\u5e16\u8be2\u95ee\u3002\u597d\u5fc3\u56de\u590d\u4f60\u7684\u4eba\u8ba9\u4f60\u7c98\u8d34\u4e0a\u6765\u4f60\u7684\/etc\/apache2\/sites-available\/default-ssl<\/strong>\u6587\u4ef6\u5185\u5bb9\u3002\u5047\u5982\u4f60\u80fd\u79fb\u9664\u6389\u6240\u6709\u7684\u6ce8\u91ca\u884c\uff0c\u90a3\u4e48\u5bf9\u4f60\uff0c\u5bf9\u5e2e\u4f60\u7684\u4eba\uff0c\u4ee5\u53ca\u6240\u6709\u9605\u8bfb\u8be5\u6587\u4ef6\u7684\u4eba\uff0c\u4e0d\u662f\u66f4\u5bb9\u6613\u53d1\u73b0\u95ee\u9898\u5417\uff1f\u4f60\u5f53\u7136\u53ef\u4ee5\u5f88\u5bb9\u6613\u7684\u505a\u5230\uff01\u53ea\u9700\u8fd9\u6837\u505a\u5c31\u53ef\u4ee5\u4e86\uff1a<\/p>\n

 $ sudo grep -v \"#\" \/etc\/apache2\/sites-available\/default-ssl<\/pre>\n

\u9009\u9879-v<\/strong>\u662f\u544a\u8bc9grep<\/strong>\u547d\u4ee4\u53cd\u8f6c\u5b83\u7684\u8f93\u51fa\u7ed3\u679c\uff0c\u610f\u601d\u5c31\u662f\u4e0d\u8f93\u51fa\u5339\u914d\u7684\u9879\uff0c\u505a\u76f8\u53cd\u7684\u4e8b\uff0c\u6253\u5370\u51fa\u6240\u6709\u4e0d\u5339\u914d\u7684\u9879\u3002\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6709#<\/strong>\u7684\u662f\u6ce8\u91ca\u884c\uff08\u8bd1\u6ce8\uff1a\u5176\u5b9e\u8fd9\u4e2a\u547d\u4ee4\u5e76\u4e0d\u51c6\u786e\uff0c\u5305\u542b\u201c#\u201d\u7684\u884c\u4e0d\u5168\u662f\u6ce8\u91ca\u884c\u3002\u5173\u4e8e\u5982\u4f55\u7cbe\u786e\u5339\u914d\u6ce8\u91ca\u884c\uff0c\u53ef\u4ee5\u4e86\u89e3\u66f4\u591a\u7684\u5173\u4e8e\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u5185\u5bb9\u3002\uff09\u3002<\/p>\n

3.\u627e\u51fa\u6240\u6709\u7684mp3\u6587\u4ef6<\/strong><\/div>\n

grep<\/strong>\u547d\u4ee4\u5bf9\u4e8e\u8fc7\u6ee4\u6765\u81ea\u4e8e\u6807\u51c6\u8f93\u51fa<\/strong>\u7684\u7ed3\u679c\u975e\u5e38\u6709\u7528\u3002\u4f8b\u5982\uff0c\u5047\u8bbe\u4f60\u7684\u4e00\u4e2a\u6587\u4ef6\u5939\u91cc\u9762\u5168\u662f\u5404\u79cd\u683c\u5f0f\u7684\u97f3\u4e50\u6587\u4ef6\u3002\u4f60\u8981\u627e\u51fa\u827a\u672f\u5bb6jayZ<\/strong>\u7684\u6240\u6709mp3<\/strong>\u683c\u5f0f\u7684\u97f3\u4e50\u6587\u4ef6\uff0c\u91cc\u9762\u4e5f\u4e0d\u8981\u6709\u4efb\u4f55\u6df7\u5408\u97f3\u8f68\u3002\u4f7f\u7528find\u547d\u4ee4<\/strong>\u518d\u7ed3\u5408\u7ba1\u9053\u4f7f\u7528grep<\/strong>\u5c31\u53ef\u4ee5\u5b8c\u6210\u8fd9\u4e2a\u9b54\u6cd5\uff1a<\/p>\n

 $ sudo find . -name \".mp3\" | grep -i JayZ | grep -vi \"remix\"<\/pre>\n

\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528find\u547d\u4ee4\u6253\u5370\u51fa\u6240\u6709\u4ee5.mp3<\/strong>\u4e3a\u540e\u7f00\u540d\u7684\u6587\u4ef6\uff0c\u63a5\u7740\u5c06\u5176\u4f7f\u7528\u7ba1\u9053\u4f20\u9012\u7ed9grep -i<\/strong>\u8fc7\u6ee4\u548c\u6253\u5370\u51fa\u540d\u5b57\u4e3a\u201cJayZ<\/strong>\u201d\u7684\u6587\u4ef6,\u518d\u4f7f\u7528\u7ba1\u9053\u4f20\u9001\u7ed9grep -vi<\/strong>\u4ee5\u4fbf\u8fc7\u6ee4\u6389\u542b\u6709\u201cremix<\/strong>\u201d\u7684\u9879\u3002<\/p>\n