{"id":110727,"date":"2024-11-30T10:54:11","date_gmt":"2024-11-30T02:54:11","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=110727"},"modified":"2024-11-30T10:54:11","modified_gmt":"2024-11-30T02:54:11","slug":"linux-swiss-sabre","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-swiss-sabre.html","title":{"rendered":"Linux\u547d\u4ee4\u884c\u91cc\u7684\u201c\u745e\u58eb\u519b\u5200\u201d"},"content":{"rendered":"
\u8fd9\u91cc\u8bf4\u7684\u201c\u745e\u58eb\u519b\u5200\u201d\u662f\u6307\u90a3\u4e9b\u7b80\u5355\u7684\u4e00\u53e5\u547d\u4ee4\u5c31\u80fd\u5b8c\u6210\u5176\u5b83\u9ad8\u7ea7\u8bed\u8a00\u4e00\u5927\u7247\u4ee3\u7801\u624d\u80fd\u5b8c\u6210\u7684\u5de5\u4f5c\u3002<\/p>\n
\u4e0b\u9762\u7684\u8fd9\u4e9b\u5185\u5bb9\u662fQuora<\/a>\u7f51\u7ad9\u4e0aJoshua Levy\u7f51\u53cb\u7684\u603b\u7ed3\uff1a<\/p>\n \u901a\u8fc7sort<\/a><\/span>\/uniq<\/a><\/span>\u83b7\u53d6\u6587\u4ef6\u5185\u5bb9\u7684\u4ea4\u96c6\u3001\u5408\u96c6\u548c\u4e0d\u540c\u4e4b\u5904\uff1a\u5047\u8bbe\u6709a\u3001b\u4e24\u4e2a\u6587\u672c\u6587\u4ef6\uff0c\u6587\u4ef6\u672c\u8eab\u5df2\u7ecf\u53bb\u9664\u4e86\u91cd\u590d\u5185\u5bb9\u3002\u4e0b\u9762\u662f\u6548\u7387\u6700\u9ad8\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5904\u7406\u4efb\u4f55\u4f53\u79ef\u7684\u6587\u4ef6\uff0c\u751a\u81f3\u51e0\u4e2aG\u7684\u6587\u4ef6\u3002(Sort\u5bf9\u5185\u5b58\u6ca1\u6709\u8981\u6c42)\u53ef\u4ee5\u8bd5\u7740\u6bd4\u8f83\u4e00\u4e0b\uff0c\u4f60\u53ef\u4ee5\u770b\u770b\u5982\u679c\u7528JAVA<\/a><\/span>\u6765\u5904\u7406\u78c1\u76d8\u4e0a\u6587\u4ef6\u7684\u5408\u5e76\uff0c\u9700\u8981\u7528\u591a\u5c11\u884c\u4ee3\u7801\u3002<\/p>\n \u6c47\u603b\u4e00\u4e2a\u6587\u672c\u5185\u5bb9\u91cc\u7b2c\u4e09\u5217\u6570\u5b57\u7684\u548c\uff0c(\u8fd9\u4e2a\u65b9\u6cd5\u8981\u6bd4\u7528Python\u6765\u505a\u5feb3\u500d\u5e76\u53ea\u97001\/3\u7684\u4ee3\u7801\u91cf)\uff1a<\/p>\n \u5982\u679c\u4f60\u60f3\u67e5\u770b\u4e00\u4e2a\u76ee\u5f55\u6811\u91cc\u7684\u6587\u4ef6\u7684\u4f53\u79ef\u548c\u4fee\u6539\u65e5\u671f\uff0c\u7528\u4e0b\u9762\u7684\u65b9\u6cd5\uff0c\u76f8\u5f53\u4e8e\u4f60\u6328\u4e2a\u76ee\u5f55\u505a\u201dls<\/a><\/span>\u00a0-l\u201d\uff0c\u800c\u4e14\u8f93\u51fa\u7684\u5f62\u5f0f\u6bd4\u4f60\u7528\u201dls -lR\u201d\u66f4\u53ef\u8bfb\uff1a<\/p>\n \u4f7f\u7528xargs<\/a><\/span>\u547d\u4ee4\u3002\u8fd9\u4e2a\u547d\u4ee4\u975e\u5e38\u7684\u5f3a\u5927\u3002\u6ce8\u610f\u6bcf\u884c\u4e0a\u4f60\u53ef\u4ee5\u63a7\u5236\u591a\u5c11\u4e2a\u4e1c\u897f\u7684\u6267\u884c\u3002\u5982\u679c\u4f60\u4e0d\u786e\u5b9a\u5b83\u662f\u6b63\u786e\u7684\u6267\u884c\uff0c\u5148\u4f7f\u7528xargs\u00a0echo<\/a><\/span>\u3002\u540c\u6837\uff0c-I{} \u4e5f\u975e\u5e38\u6709\u7528\u3002\u4f8b\u5b50\uff1a<\/p>\n \u5047\u8bbe\u4f60\u6709\u4e00\u4e2a\u6587\u672c\u6587\u4ef6\uff0c\u6bd4\u5982\u4e00\u4e2aweb\u670d\u52a1\u5668\u65e5\u5fd7\uff0c\u5728\u67d0\u4e9b\u884c\u4e0a\u6709\u4e00\u4e9b\u503c\uff0c\u6bd4\u5982URL\u4e2d\u7684acct_id\u53c2\u6570\u3002\u5982\u679c\u4f60\u60f3\u7edf\u8ba1\u6bcf\u4e2aacct_id\u7684\u6240\u6709\u8bf7\u6c42\u8bb0\u5f55\uff1a<\/p>\n \u539f\u6587\u6765\u81ea\uff1ahttps:\/\/www.oschina.net\/news\/41214\/what-are-the-most-useful-swiss-army-knife-one-liners-on-unix<\/a><\/p>\ncat<\/a><\/span> a b | sort | uniq > c # c \u662fa\u548cb\u7684\u5408\u96c6\r\ncat a b | sort | uniq -d > c # c \u662fa\u548cb\u7684\u4ea4\u96c6\r\ncat a b b | sort | uniq -u > c # c \u662fa\u548cb\u7684\u4e0d\u540c<\/pre>\n
awk<\/a><\/span> \u2018{ x += $3 } END { print x }\u2019 myfile<\/pre>\n
find<\/a><\/span> . -type<\/a><\/span> f -ls<\/pre>\n
find . -name \\*.py | xargs grep<\/a><\/span> some_function\r\ncat hosts | xargs -I{} ssh<\/a><\/span> root@{} hostname<\/a><\/span><\/pre>\n
cat access.log | egrep<\/a><\/span> -o \u2018acct_id=[0-9]+\u2019 | cut<\/a><\/span> -d= -f2 | sort | uniq -c | sort -rn<\/pre>\n
\n