{"id":290828,"date":"2024-04-12T05:12:20","date_gmt":"2024-04-11T21:12:20","guid":{"rendered":"https:\/\/lrxjmw.cn\/lcdxdjmrhbhc.html"},"modified":"2024-04-12T05:12:20","modified_gmt":"2024-04-11T21:12:20","slug":"lcdxdjmrhbhc","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/lcdxdjmrhbhc.html","title":{"rendered":"Linux\u91cd\u5b9a\u5411\u5927\u63ed\u79d8\uff1a2>&1\u5982\u4f55\u6355\u83b7\u9519\u8bef\u4fe1\u606f\uff1f"},"content":{"rendered":"

\u5728Linux<\/a>\u64cd\u4f5c\u7cfb\u7edf<\/a>\u4e2d\uff0c\u91cd\u5b9a\u5411\u5177\u6709\u6781\u5176\u91cd\u8981\u7684\u4f5c\u7528\u3002\u501f\u52a9\u8be5\u529f\u80fd\uff0c\u53ef\u5c06\u547d\u4ee4<\/a>\u8f93\u51fa\u5bfc\u5411\u81f3\u6587\u4ef6\u3001\u6253\u5370\u673a\u6216\u53e6\u4e00\u6761\u6307\u4ee4\u7b49\u76ee\u7684\u5730\u3002\u5c24\u5176\u503c\u5f97\u6ce8\u610f\u7684\u662f\"2>&1\"\u8fd9\u4e00\u7279\u6b8a\u5f62\u5f0f\u7684\u91cd\u5b9a\u5411\uff0c\u80fd\u5c06\u6807\u51c6\u9519\u8bef\u4e0e\u6807\u51c6\u8f93\u51fa\u5408\u5e76\u6210\u5355\u4e00\u6d41\uff0c\u4ece\u800c\u66f4\u6709\u6548\u5730\u6355\u6349\u547d\u4ee4\u6267\u884c\u8fc7\u7a0b\u4e2d\u7684\u9519\u8bef\u4fe1\u606f\u3002\u672c\u7bc7\u6587\u7ae0\u5c06\u8be6\u7ec6\u89e3\u6790Linux\u91cd\u5b9a\u5411\u53ca\"2>&1\"\u7684\u8fd0\u7528\u65b9\u6cd5\u53ca\u5176\u5b9e\u9645\u5e94\u7528\u6848\u4f8b\u3002<\/p>\n

1.\u91cd\u5b9a\u5411\u57fa\u7840<\/b><\/p>\n

\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u91cd\u5b9a\u5411\u64cd\u4f5c\u4e3b\u8981\u501f\u52a9\u4e8e\u7279\u5b9a\u5b57\u7b26\u8fdb\u884c\u5b9e\u73b0\uff0c\">\"\u8868\u793a\u5c06\u547d\u4ee4\u6267\u884c\u7ed3\u679c\u8f93\u51fa\u81f3\u6307\u5b9a\u6587\u4ef6\uff08\u82e5\u6587\u4ef6\u4e0d\u5b58\uff0c\u81ea\u52a8\u65b0\u5efa\uff09\uff1b\">>\"\u5219\u4e3a\u7eed\u589e\u6a21\u5f0f\uff0c\u5c06\u8f93\u51fa\u6570\u636e\u8ffd\u52a0\u81f3\u76ee\u6807\u6587\u4ef6\u5c3e\u90e8\u3002\u4f8b\u5982\uff1a<\/p>\n

\n

bash\nls > file.txt\n<\/pre>\n<\/p>\n

\u6b64\u547d\u4ee4\u53ef\u5b9e\u73b0\u5f53\u524d\u76ee\u5f55\u6587\u4ef6\u6e05\u5355\u7684\u5bfc\u51fa\u81f3file.txt\u6587\u6863\u3002\u82e5\u9700\u540c\u65f6\u6db5\u76d6\u6807\u51c6\u8f93\u51fa\u4e0e\u9519\u8bef\u8f93\u51fa\u5230\u540c\u4e00\u6587\u6863\uff0c\u5219\u9700\u5f15\u7528\"2>&1\"\u8fd9\u4e00\u6a21\u5f0f\u3002<\/p>\n

2.\u7406\u89e32>&1<\/b><\/p>\n

\u5728Linux\u64cd\u4f5c\u7cfb\u7edf\u4e0b\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u90fd\u5177\u59070\u30011\u4ee5\u53ca2\u8fd9\u4e09\u4e2a\u6807\u51c6\u6587\u4ef6\u63cf\u8ff0\u7b26\uff1a\u5176\u4e2d\uff0c0\u4ee3\u8868\u6807\u51c6\u8f93\u5165\uff0c1\u4ee3\u8868\u6807\u51c6\u8f93\u51falinux\u7cfb\u7edf\u5165\u95e8\u5b66\u4e60\uff0c\u800c2\u5219\u8868\u793a\u6807\u51c6\u9519\u8bef\u3002\u6bcf\u5f53\u6267\u884c\u547d\u4ee4\u65f6\uff0c\u5c06\u4f1a\u751f\u6210\u4e24\u7c7b\u8f93\u51fa\uff0c\u5373\u6807\u51c6\u8f93\u51fa\u4e0e\u6807\u51c6\u9519\u8bef\u3002\u800c\"2>&1\"\u8fd9\u4e2a\u91cd\u5b9a\u5411\u7b26\uff0c\u5176\u771f\u6b63\u542b\u4e49\u4fbf\u662f\u901a\u8fc7\u5c06\u6807\u51c6\u9519\u8bef\uff082\uff09\u91cd\u5b9a\u5411\u81f3\u6807\u51c6\u8f93\u51fa\uff081\uff09\uff0c\u4ece\u800c\u5b9e\u73b0\u4e24\u8005\u7684\u5408\u6d41\u3002<\/p>\n

command > file.txt 2>&1<\/p>\n

\u6b64\u6307\u4ee4\u5c06\u786e\u4fdd\u5c06`command`\u7684\u6807\u51c6\u4ea7\u51fa\u548c\u9519\u8bef\u8baf\u606f\u5747\u5b8c\u6574\u8bb0\u5f55\u81f3\u6587\u4ef6`file.txt`\u3002\u5982\u6b64\u53ef\u52a9\u529b\u6211\u4eec\u5168\u65b9\u4f4d\u76d1\u6d4b\u53ca\u5206\u6790\u547d\u4ee4\u8fd0\u884c\u8fc7\u7a0b\u6240\u751f\u6210\u7684\u5404\u7c7b\u6570\u636e\u3002<\/p>\n

3.\u5b9e\u9645\u5e94\u7528\u573a\u666f<\/b><\/p>\n

\u5728\u5b9e\u8df5\u64cd\u4f5c\u8fc7\u7a0b\u4e2d\uff0c\u5bf9\u67d0\u4e9b\u7e41\u590d\u6307\u4ee4\u6216\u662f\u5267\u672c\u7684\u5904\u7406\u8fc7\u7a0b\u4e2d\uff0c\u5b9e\u65f6\u83b7\u53d6\u6807\u51c6\u8f93\u51fa\u4e0e\u9519\u8bef\u4fe1\u606f\u5c24\u4e3a\u91cd\u8981\uff0c\u8fd9\u6709\u52a9\u4e8e\u95ee\u9898\u7684\u5c3d\u65e9\u53d1\u73b0\u53ca\u89e3\u51b3\u3002\u4ee5\u4e0b\u5c06\u4ee5\u4e00\u4e2a\u5177\u4f53\u6848\u4f8b\uff0c\u9610\u8ff0\u5982\u4f55\u8fd0\u7528\u201c2>&1\u201d\u89c4\u5219\u3002<\/p>\n

#!\/bin\/bash<\/p>\n

ls \/root > output.txt 2>&1<\/p>\n

\u6b64\u811a\u672c\u5c06\u8be6\u5c3d\u5c55\u793a\/root \u76ee\u5f55\u4e2d\u7684\u6240\u6709\u6587\u4ef6\u548c\u5b50\u76ee\u5f55\uff0c\u540c\u65f6\u5c06\u5176\u76f8\u5173\u8fd0\u884c\u72b6\u6001\u53ca\u9519\u8bef\u4fe1\u606f\u4f9d\u6b21\u8bb0\u5f55\u4e8e output.txt \u6587\u4ef6\u4e2d\u3002\u5982\u6b64\u4e00\u6765\uff0c\u4fbf\u53ef\u5728\u5fc5\u8981\u4e4b\u65f6\u65b9\u4fbf\u5730\u67e5\u770b\u5177\u4f53\u6267\u884c\u72b6\u51b5\uff0c\u8fc5\u901f\u534f\u52a9\u6211\u4eec\u786e\u5b9a\u95ee\u9898\u6240\u5728\u3002<\/p>\n

4.\u9519\u8bef\u5904\u7406\u4e0e\u8c03\u8bd5<\/b><\/p>\n

\u5728Shell script\u7684\u7f16\u5199\u548c\u7e41\u590d\u6307\u4ee4\u7684\u6267\u884c\u4e2d\uff0c\u6211\u4eec\u5e38\u5e38\u906d\u9047\u610f\u6599\u4e4b\u5916\u7684\u72b6\u51b5\u4ee5\u53ca\u5404\u7c7b\u9519\u8bef\u63d0\u793a\u3002\u91cd\u5b9a\u5411\u6280\u672f\u7684\u7075\u6d3b\u8fd0\u7528\u4e3a\u9519\u8bef\u5904\u7406\u53ca\u8c03\u8bd5\u5de5\u4f5c\u63d0\u4f9b\u4e86\u6709\u6548\u7684\u89e3\u51b3\u65b9\u6848\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8c03\u8bd5\u9636\u6bb5\u53ef\u5229\u7528\u6b64\u529f\u80fd\u5c06\u6240\u6709\u8f93\u51fa\u6570\u636e\u59a5\u5584\u5b58\u50a8\u81f3\u65e5\u5fd7\u6587\u4ef6\u4e4b\u4e2d\uff1a<\/p>\n

.\/script.sh > log.txt 2>&1<\/p>\n

\u5982\u6b64\u4e00\u6765\u7ea2\u5e3dlinux\u7cfb\u7edf\u4e0b\u8f7d\uff0c\u5373\u4fbf\u6307\u4ee4\u64cd\u4f5c\u5931\u8d25\u6216\u8005\u53d1\u751f\u5f02\u5e38\uff0c\u6211\u4eec\u4ea6\u53ef\u501f\u52a9\u68c0\u67e5\u65e5\u5fd7\u6587\u4ef6\u8fc5\u901f\u786e\u5b9a\u95ee\u9898\u7684\u4f4d\u7f6e\uff0c\u4fbf\u6377\u5730\u8fdb\u884c\u76f8\u5e94\u8c03\u6574\u3002<\/p>\n

5.\u65e5\u5e38\u5de5\u4f5c\u4f18\u5316<\/b><\/p>\n

\u91cd\u5b9a\u5411\u6280\u672f\u7684\u5b9e\u9645\u5e94\u7528\u8fdc\u4e0d\u5c40\u9650\u4e8e\u5f00\u53d1\u4e0e\u8c03\u8bd5\u9636\u6bb5linux \u91cd\u5b9a\u5411 2 1<\/strong>\uff0c\u5176\u5728\u65e5\u5e38\u5de5\u4f5c\u4e2d\u7684\u4ef7\u503c\u4ea6\u4e0d\u5bb9\u5ffd\u89c6\u3002\u4f8b\u5982\uff0c\u5927\u6279\u91cf\u6570\u636e\u5904\u7406\u540e\u7684\u7ed3\u679c\u53ef\u88ab\u5b89\u5168\u5730\u5b58\u50a8\u81f3\u65e5\u5fd7\u6587\u4ef6\u4ee5\u5907\u672a\u6765\u5206\u6790\u4e4b\u9700\uff1b\u53c8\u5982\uff0c\u81ea\u52a8\u4efb\u52a1\u6267\u884c\u671f\u95f4\u6355\u83b7\u5173\u952e\u4fe1\u606f\u6709\u52a9\u4e8e\u5b9e\u65f6\u76d1\u6d4b\u7a0b\u5e8f\u72b6\u51b5\u3002<\/p>\n

backup.sh > backup.log 2>&1<\/p>\n

\u8fd9\u6837\u5c31\u80fd\u591f\u5b9e\u65f6\u8bb0\u5f55\u5907\u4efd\u4efb\u52a1\u6267\u884c\u60c5\u51b5\u5e76\u53ca\u65f6\u53d1\u73b0\u5f02\u5e38\u3002<\/p>\n

6.\u811a\u672c\u7f16\u5199\u6280\u5de7<\/b><\/p>\n

Linux\u8d44\u6df1\u8fd0\u7ef4\u4eba\u5458\u53ef\u901a\u8fc7\u5de7\u5999\u8fd0\u7528\u91cd\u5b9a\u5411\u6280\u672f\u4e8e\u811a\u672c\u7f16\u5199\uff0c\u63d0\u5347\u5de5\u4f5c\u6548\u7387\u4e0e\u65b9\u6848\u7a33\u5b9a\u6027\u3002\u4f8b\u5982\uff0c\u5b9e\u65f6\u76d1\u63a7\u6570\u636e\u5904\u7406\u6d41\u7a0b\u4e0e\u6355\u83b7\u4efb\u52a1\u6267\u884c\u5173\u952e\u73af\u8282\u4fe1\u606f\u7b49\u3002<\/p>\n

for file in *.txt; do<\/p>\n

\u5c06\u6587\u4ef6$file\u4ee5\u8ffd\u52a0\u6a21\u5f0f\u5199\u5165\u81f3\u5904\u7406\u65e5\u5fd7\u4e2d\uff0c\u540c\u65f6\u5c06\u64cd\u4f5c\u9519\u8bef\u4fe1\u606f\u4e5f\u5408\u5e76\u5199\u5165\uff082>&1\uff09\u3002<\/p>\n

done<\/p>\n

\u5982\u6b64\u63aa\u65bd\u65e2\u53ef\u786e\u4fdd\u8be6\u5c3d\u7684\u5904\u7406\u65e5\u5fd7\u5f97\u4ee5\u4fdd\u5b58\uff0c\u53c8\u80fd\u8fc5\u901f\u5b9a\u4f4d\u95ee\u9898\u5e76\u5b9e\u65bd\u6545\u969c\u4fee\u590d\u3002<\/p>\n

7.\u5b89\u5168\u6ce8\u610f\u4e8b\u9879<\/b><\/p>\n

\u867d\u7136\u91cd\u5b9a\u5411\u529f\u80fd\u5f3a\u5927linux \u91cd\u5b9a\u5411 2 1<\/strong>\uff0c\u4f46\u5e94\u614e\u91cd\u8003\u8651\u5176\u5b89\u5168\u6027\u3002\u5c24\u5176\u5f53\u5904\u7406\u654f\u611f\u8d44\u6599\u6216\u8005\u6267\u884c\u5177\u6709\u9ad8\u6743\u9650\u7684\u64cd\u4f5c\u65f6\uff0c\u987b\u683c\u5916\u8c28\u614e\uff0c\u9632\u6b62\u56e0\u8bbe\u7f6e\u5931\u8bef\u800c\u9020\u6210\u4fe1\u606f\u6cc4\u6f0f\u53ca\u5f15\u53d1\u7cfb\u7edf\u98ce\u9669\u3002<\/p>\n

\u5c06`password123`\u8ffd\u52a0\u5199\u5165\u5bc6\u7801\u6587\u4ef6\uff0c\u9700\u6ce8\u610f\u6b64\u64cd\u4f5c\u5b58\u5728\u4e00\u5b9a\u98ce\u9669\u6027\u3002\u4e0d\u5efa\u8bae\u5728\u6587\u4e2d\u76f4\u63a5\u6cc4\u9732\u6216\u50a8\u5b58\u4efb\u4f55\u673a\u5bc6\u4fe1\u606f\u3002<\/p>\n

\u5e94\u907f\u5f00\u653e\u9732\u654f\u611f\u6570\u636e\u4e8e\u660e\u6587\u660e\u6863\uff0c\u4e14\u4ec5\u6388\u6743\u4eba\u58eb\u6709\u6743\u5229\u67e5\u9605\u76f8\u5173\u65e5\u5fd7\u53ca\u7eaa\u5f55\u3002<\/p>\n

8.\u8fdb\u9636\u5e94\u7528\u793a\u4f8b<\/b><\/p>\n

\u9664\u57fa\u7840\u5e94\u7528\u65b9\u5f0f\u5916\uff0c\u201c2>&1\u201d\u4ea6\u53ef\u4e0e\u7ba1\u9053\u53ca\u5b50 shell \u65bd\u884c\u7075\u6d3b\u800c\u6df1\u5165\u7684\u64cd\u4f5c\u6307\u4ee4\u3002\u5982\u5728\u7ba1\u9053\u64cd\u4f5c\u8fc7\u7a0b\u4e2d\uff0c\u540c\u6b65\u6536\u96c6\u6240\u6709\u6d41\u4fe1\u606f\uff1a<\/p>\n

\u547d\u4ee41`|`\u547d\u4ee42`>>>`\u8f93\u51fa\u65e5\u5fd7\u6587\u4ef6<\/p>\n

\u7efc\u5408\u6267\u884c\u547d\u4ee41\u53ca\u547d\u4ee42\uff0c\u5c06\u6240\u6709\u8f93\u5165\/\u8f93\u51fa\u6d41\u8bb0\u5f55\u4e8eoutput.log\uff0c\u6b64\u7c7b\u7ec4\u5408\u8fd0\u7528\u4e3a\u8d44\u6df1\u7528\u6237\u8d4b\u4e88\u66f4\u5e7f\u9614\u7684\u5e94\u7528\u7a7a\u95f4\u3002<\/p>\n

9.\u603b\u7ed3\u4e0e\u5c55\u671b<\/b><\/p>\n

\u901a\u8fc7\u672c\u6587\u5bf9Linux\u91cd\u5b9a\u5411\u53ca\"2>&1\"\u8fd9\u4e00\u5173\u952e\u6982\u5ff5\u7684\u8be6\u5c3d\u89e3\u8bfb\uff0c\u6211\u4eec\u6df1\u5165\u638c\u63e1\u5176\u57fa\u7840\u6982\u5ff5\u5e76\u5b66\u4f1a\u4e86\u5982\u4f55\u5728\u5b9e\u9645\u5de5\u4f5c\u73af\u5883\u4e0b\u7075\u6d3b\u8fd0\u7528\u8fd9\u4e9b\u77e5\u8bc6\u70b9\u6765\u89e3\u51b3\u95ee\u9898\u4ee5\u53ca\u4f18\u5316\u7a0b\u5e8f\u6027\u80fd\u3002\u968f\u7740\u79d1\u6280\u7684\u65e5\u65b0\u6708\u5f02\u4ee5\u53ca\u5e94\u7528\u9886\u57df\u7684\u6269\u5f20\uff0c\u6211\u4eec\u6709\u7406\u7531\u76f8\u4fe1\uff0c\u91cd\u5b9a\u5411\u529f\u80fd\u5c06\u5728\u672a\u6765\u7684\u7cfb\u7edf\u7ba1\u7406\u548c\u5f00\u53d1\u5b9e\u8df5\u4e2d\u53d1\u6325\u66f4\u4e3a\u91cd\u8981\u7684\u4f5c\u7528\u3002<\/p>\n

\u671f\u671b\u4ece\u9605\u8bfb\u6b64\u6587\u7684\u8fc7\u7a0b\u4e2d\uff0c\u60a8\u80fd\u66f4\u52a0\u6df1\u5165\u5730\u9886\u609fLinux \u7cfb\u7edf\u4e2d\u7684\u91cd\u5b9a\u5411\u529f\u80fd\uff0c\u5e76\u5728\u5b9e\u8df5\u4e2d\u6d3b\u7528\u8fd9\u4e9b\u6280\u672f\u6765\u63d0\u5347\u5de5\u4f5c\u6548\u7387\u548c\u7a33\u5b9a\u6027\u3002\u8bf7\u8e0a\u8dc3\u5206\u4eab\u60a8\u5bf9\u4e8e Linux \u91cd\u5b9a\u5411\u4ee5\u53ca\"2>&1\"\u7684\u89c1\u89e3\u4ee5\u53ca\u5b9e\u9645\u8fd0\u7528\u7ecf\u9a8c\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5c24\u5176\u503c\u5f97\u6ce8\u610f\u7684\u662f2>&1\u8fd9\u4e00\u7279\u6b8a\u5f62\u5f0f\u7684\u91cd\u5b9a\u5411\uff0c\u80fd\u5c06\u6807\u51c6\u9519\u8bef\u4e0e\u6807\u51c6\u8f93\u51fa\u5408\u5e76\u6210\u5355\u4e00\u6d41\uff0c\u4ece\u800c\u66f4\u6709\u6548\u5730\u6355\u6349\u547d\u4ee4\u6267\u884c\u8fc7\u7a0b\u4e2d\u7684\u9519\u8bef\u4fe1\u606f\u3002\u4ee5\u4e0b\u5c06\u4ee5\u4e00\u4e2a\u5177\u4f53\u6848\u4f8b\uff0c\u9610\u8ff0\u5982\u4f55\u8fd0\u7528\u201c2>&1\u201d\u89c4\u5219\u3002\u547d\u4ee41`|`\u547d\u4ee42`>>>`\u8f93\u51fa\u65e5\u5fd7\u6587\u4ef6<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[999],"class_list":["post-290828","post","type-post","status-publish","format-standard","hentry","category-tougao","tag-999"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/290828","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=290828"}],"version-history":[{"count":0,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/290828\/revisions"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=290828"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=290828"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=290828"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}