{"id":153495,"date":"2019-09-16T11:46:16","date_gmt":"2019-09-16T03:46:16","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=153495"},"modified":"2019-08-29T15:47:25","modified_gmt":"2019-08-29T07:47:25","slug":"linux-delete-content","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-delete-content.html","title":{"rendered":"\u5982\u4f55\u5728 Linux \u4e2d\u5220\u9664\u76ee\u5f55"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u6709\u51e0\u79cd\u4e0d\u540c\u7684\u65b9\u6cd5\u53ef\u4ee5\u5220\u9664 Linux \u7cfb\u7edf\u4e2d\u7684\u76ee\u5f55\u3002\u5982\u679c\u60a8\u4f7f\u7528\u684c\u9762\u6587\u4ef6\u7ba1\u7406\u5668(\u5982 Gnome \u7684\u6587\u4ef6\u7ba1\u7406\u5668\u6216 KDE \u7684 Dolphin) \uff0c\u5219\u53ef\u4ee5\u4f7f\u7528\u7ba1\u7406\u5668\u7684\u56fe\u5f62\u7528\u6237\u754c\u9762\u5220\u9664\u6587\u4ef6\u548c\u76ee\u5f55\u3002\u4f46\u662f\uff0c\u5982\u679c\u60a8\u6b63\u5728\u4f7f\u7528\u65e0\u5934\u670d\u52a1\u5668\u6216\u60f3\u8981\u4e00\u6b21\u5220\u9664\u591a\u4e2a\u76ee\u5f55\uff0c\u6700\u597d\u7684\u9009\u62e9\u662f\u4ece\u547d\u4ee4\u884c\u5220\u9664\u76ee\u5f55(\u6587\u4ef6\u5939)\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 rmdir \uff0c rm \u548c find \u547d\u4ee4\u5220\u9664 Linux \u4e2d\u7684\u76ee\u5f55\u3002<\/p>\n

\u5728\u4f60\u5f00\u59cb\u4e4b\u524d<\/p>\n

\u4f7f\u7528\u684c\u9762\u6587\u4ef6\u7ba1\u7406\u5668\u5220\u9664\u76ee\u5f55\u65f6\uff0c\u8be5\u76ee\u5f55\u5b9e\u9645\u4e0a\u5df2\u79fb\u81f3\u201c\u5e9f\u7eb8\u7bd3\u201d\uff0c\u5e76\u4e14\u53ef\u4ee5\u8f7b\u677e\u6062\u590d\u3002<\/p>\n

\u4ece\u547d\u4ee4\u884c\u5220\u9664\u6587\u4ef6\u6216\u76ee\u5f55\u65f6\u8981\u683c\u5916\u5c0f\u5fc3\uff0c\u56e0\u4e3a\u4e00\u65e6\u4f7f\u7528\u672c\u6587\u4e2d\u4ecb\u7ecd\u7684\u547d\u4ee4\u5220\u9664\u76ee\u5f55\uff0c\u5c31\u65e0\u6cd5\u5b8c\u5168\u6062\u590d\u3002<\/p>\n

\u5728\u5927\u591a\u6570 Linux \u6587\u4ef6\u7cfb\u7edf\u4e0a\uff0c\u5220\u9664\u76ee\u5f55\u9700\u8981\u5bf9\u76ee\u5f55\u53ca\u5176\u5185\u5bb9\u5177\u6709\u5199\u6743\u9650\u3002\u5426\u5219\u60a8\u5c06\u6536\u5230\u201c\u4e0d\u5141\u8bb8\u64cd\u4f5c\u201d\u9519\u8bef\u3002<\/p>\n

\u5fc5\u987b\u4f7f\u7528\u53cd\u659c\u6760 (\/) \u8f6c\u4e49\u5176\u4e2d\u5305\u542b\u7a7a\u683c\u7684\u76ee\u5f55\u540d\u79f0\u3002<\/p>\n

\u5220\u9664\u76ee\u5f55 rmdir<\/strong><\/div>\n

rmdir \u662f\u4e00\u4e2a\u7528\u4e8e\u5220\u9664\u7a7a\u76ee\u5f55\u7684\u547d\u4ee4\u884c\u5b9e\u7528\u7a0b\u5e8f\u3002\u53ea\u6709\u5f53\u76ee\u5f55\u4e3a\u7a7a\u65f6\u624d\u9700\u8981\u5220\u9664\u76ee\u5f55\uff0c\u800c\u4e0d\u9700\u8981\u68c0\u67e5\u76ee\u5f55\u662f\u5426\u4e3a\u7a7a\u3002<\/p>\n

\u8981\u5220\u9664\u76ee\u5f55 rmdir \uff0c\u8bf7\u952e\u5165\u547d\u4ee4\uff0c\u7136\u540e\u952e\u5165\u8981\u5220\u9664\u7684\u76ee\u5f55\u7684\u540d\u79f0\u3002\u4f8b\u5982\uff0c\u8981\u5220\u9664\u540d\u4e3a linuxmi \u7684\u76ee\u5f55\uff0c\u8bf7\u952e\u5165\uff1a<\/p>\n

\r\nlinuxidc@linuxidc:~$ rmdir linuxmi\r\n<\/pre>\n

\u5982\u679c\u76ee\u5f55\u4e0d\u4e3a\u7a7a\uff0c\u60a8\u5c06\u6536\u5230\u4ee5\u4e0b\u9519\u8bef\uff1a<\/p>\n

rmdir: \u5220\u9664 'linuxmi' \u5931\u8d25: \u76ee\u5f55\u975e\u7a7a<\/p>\n

\"\"<\/p>\n

\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u60a8\u9700\u8981\u4f7f\u7528\u8be5 rm \u547d\u4ee4\u6216\u624b\u52a8\u5220\u9664\u76ee\u5f55\u5185\u5bb9\uff0c\u7136\u540e\u624d\u80fd\u5220\u9664\u5b83\u3002<\/p>\n

\u5220\u9664\u76ee\u5f55 rm<\/strong><\/div>\n

rm \u662f\u4e00\u4e2a\u7528\u4e8e\u5220\u9664\u6587\u4ef6\u548c\u76ee\u5f55\u7684\u547d\u4ee4\u884c\u5b9e\u7528\u7a0b\u5e8f\u3002\u4e0e\u547d\u4ee4\u4e0d\u540c rmdir, rm \u53ef\u4ee5\u5220\u9664\u7a7a\u76ee\u5f55\u548c\u975e\u7a7a\u76ee\u5f55\u3002<\/p>\n

\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5728\u6ca1\u6709\u4efb\u4f55\u9009\u9879\u7684\u60c5\u51b5\u4e0b\u4f7f\u7528\u65f6 rm \u4e0d\u4f1a\u5220\u9664\u76ee\u5f55 \u8981\u5220\u9664\u7a7a\u76ee\u5f55\uff0c\u8bf7\u4f7f\u7528 -d(--dir) \u9009\u9879\u3002 \u5982\u679c\u8981\u5220\u9664\u975e\u7a7a\u76ee\u5f55\u548c\u5176\u4e2d\u7684\u6240\u6709\u5185\u5bb9\uff0c\u8bf7\u4f7f\u7528 -r(--recursive \u6216 -R) \u9009\u9879\u3002<\/p>\n

\u4f8b\u5982\uff0c\u8981\u5220\u9664\u4e00\u4e2a\u540d\u4e3a linuxmi \u53ca\u5176\u6240\u6709\u5185\u5bb9\u7684\u76ee\u5f55\uff0c\u60a8\u53ef\u4ee5\u952e\u5165\uff1a<\/p>\n

\r\nrm -r linuxmi\r\n<\/pre>\n

\u5982\u679c\u76ee\u5f55\u4e2d\u7684\u76ee\u5f55\u6216\u6587\u4ef6\u53d7\u5230\u5199\u4fdd\u62a4\uff0c\u7cfb\u7edf\u5c06\u63d0\u793a\u60a8\u786e\u8ba4\u5220\u9664\u3002\u8981\u5728\u4e0d\u63d0\u793a\u7684\u60c5\u51b5\u4e0b\u5220\u9664\u76ee\u5f55\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b -f \u9009\u9879\uff1a<\/p>\n

\r\nrm -r dirname\r\n<\/pre>\n

\u8981\u4e00\u6b21\u5220\u9664\u591a\u4e2a\u76ee\u5f55\uff0c\u8bf7\u4f7f\u7528 rm \u547d\u4ee4\uff0c\u540e\u8ddf\u7531\u7a7a\u683c\u5206\u9694\u7684\u76ee\u5f55\u540d\u79f0\u3002\u4e0b\u9762\u7684\u547d\u4ee4\u5c06\u5220\u9664\u6bcf\u4e2a\u5217\u51fa\u7684\u76ee\u5f55\u53ca\u5176\u5185\u5bb9\uff1a<\/p>\n

\r\nrm -r linuxmi linuxmi linuxidc\r\n<\/pre>\n

\u8be5 -i \u9009\u9879\u544a\u8bc9 rm \u63d0\u793a\u60a8\u786e\u8ba4\u5220\u9664\u6bcf\u4e2a\u5b50\u76ee\u5f55\u548c\u6587\u4ef6\u3002\u5982\u679c\u76ee\u5f55\u5305\u542b\u5927\u91cf\u6587\u4ef6\uff0c\u8fd9\u53ef\u80fd\u6709\u70b9\u70e6\u4eba\uff0c\u56e0\u6b64\u60a8\u53ef\u4ee5\u8003\u8651\u4f7f\u7528 -I \u5728\u7ee7\u7eed\u5220\u9664\u4e4b\u524d\u53ea\u63d0\u793a\u60a8\u4e00\u6b21\u7684\u9009\u9879\u3002<\/p>\n

\r\nrm -rI linuxidc\r\n<\/pre>\n

\u786e\u5b9a\u8981\u5220\u9664\u76ee\u5f55\u8bf7\u8f93\u5165 y \u5e76\u70b9\u51fb Enter \u3002<\/p>\n

\r\nrm: remove 1 argument recursively? y\r\n<\/pre>\n

\"\"<\/p>\n

\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5e38\u89c4\u6269\u5c55\u6765\u5339\u914d\u548c\u5220\u9664\u591a\u4e2a\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u8981\u5220\u9664\u5f53\u524d\u76ee\u5f55\u4e2d\u4ee5\u6240\u6709 _bak \u7ed3\u5c3e\u7684\u6240\u6709\u7b2c\u4e00\u7ea7\u76ee\u5f55\u6216\u8005\u6587\u4ef6 \uff0c\u60a8\u5c06\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

\r\nrm -r *_bak\r\n<\/pre>\n

\u5220\u9664\u76ee\u5f55\u65f6\u4f7f\u7528\u5e38\u89c4\u6269\u5c55\u53ef\u80fd\u5b58\u5728\u98ce\u9669\u3002\u5efa\u8bae\u9996\u5148\u4f7f\u7528\u8be5 ls \u547d\u4ee4\u5217\u51fa\u76ee\u5f55\uff0c\u4ee5\u4fbf\u5728\u8fd0\u884c rm \u547d\u4ee4\u4e4b\u524d\u67e5\u770b\u5c06\u5220\u9664\u7684\u76ee\u5f55\u3002<\/p>\n

\u5220\u9664\u76ee\u5f55 find<\/strong><\/div>\n

find \u662f\u4e00\u4e2a\u547d\u4ee4\u884c\u5b9e\u7528\u7a0b\u5e8f\uff0c\u5141\u8bb8\u60a8\u6839\u636e\u7ed9\u5b9a\u7684\u8868\u8fbe\u5f0f\u641c\u7d22\u6587\u4ef6\u548c\u76ee\u5f55\uff0c\u5e76\u5bf9\u6bcf\u4e2a\u5339\u914d\u7684\u6587\u4ef6\u6216\u76ee\u5f55\u6267\u884c\u64cd\u4f5c\u3002<\/p>\n

\u6700\u5e38\u89c1\u7684\u60c5\u51b5\u662f\u4f7f\u7528 find \u547d\u4ee4\u6839\u636e\u6a21\u5f0f\u5220\u9664\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u8981\u5220\u9664\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u4e2d\u6240\u6709\u4ee5 _cache \u7ed3\u5c3e\u7684\u76ee\u5f55\uff0c\u8bf7\u8fd0\u884c\uff1a<\/p>\n

\r\nfind . -type d -name '*_cache' -exec rm -r {} +\r\n<\/pre>\n

\"\"<\/p>\n

\u8ba9\u6211\u4eec\u5206\u6790\u4e00\u4e0b\u4e0a\u9762\u7684\u547d\u4ee4\uff1a
\n\u2022.- \u9012\u5f52\u641c\u7d22\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55(.)\u3002
\n\u2022-type d - \u5c06\u641c\u7d22\u9650\u5236\u4e3a\u76ee\u5f55\u3002
\n\u2022-name '*_cache' - \u4ec5\u641c\u7d22\u4ee5 _cache \u7ed3\u5c3e\u7684\u76ee\u5f55
\n\u2022-exec - \u6267\u884c\u5e26\u6709\u53ef\u9009\u53c2\u6570\u7684\u5916\u90e8\u547d\u4ee4\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u662f rm -r \u3002
\n\u2022{} +- \u5c06\u627e\u5230\u7684\u6587\u4ef6\u8ffd\u52a0\u5230 rm \u547d\u4ee4\u7684\u672b\u5c3e\u3002<\/p>\n

\u5220\u9664\u6240\u6709\u7a7a\u76ee\u5f55<\/strong><\/div>\n

\u8981\u5220\u9664\u76ee\u5f55\u6811\u4e2d\u7684\u6240\u6709\u7a7a\u76ee\u5f55\uff0c\u60a8\u5c06\u4f7f\u7528\uff1a<\/p>\n

\r\nfind \/dir -type d -empty -delete\r\n<\/pre>\n

\u4ee5\u4e0b\u662f\u5bf9\u6240\u7528\u9009\u9879\u7684\u89e3\u91ca\uff1a
\n\u2022\/dir- \u9012\u5f52\u641c\u7d22 \/dir \u76ee\u5f55\u3002
\n\u2022-type d - \u5c06\u641c\u7d22\u9650\u5236\u4e3a\u76ee\u5f55\u3002
\n\u2022-empty - \u5c06\u641c\u7d22\u9650\u5236\u4e3a\u4ec5\u7a7a\u76ee\u5f55\u3002
\n\u2022-delete - \u5220\u9664\u5b50\u6811\u4e2d\u6240\u6709\u627e\u5230\u7684\u7a7a\u76ee\u5f55\u3002 -delete \u53ea\u80fd\u5220\u9664\u7a7a\u76ee\u5f55\u3002<\/p>\n

\u8bf7\u8c28\u614e\u4f7f\u7528 -delete \u9009\u9879\u3002 find \u547d\u4ee4\u884c\u88ab\u8ba1\u7b97\u4e3a\u8868\u8fbe\u5f0f\uff0c\u5982\u679c\u9996\u5148\u6dfb\u52a0\u8be5 -delete \u9009\u9879\uff0c\u8be5\u547d\u4ee4\u5c06\u5220\u9664\u6307\u5b9a\u8d77\u59cb\u70b9\u4e0b\u65b9\u7684\u6240\u6709\u5185\u5bb9\u3002\u59cb\u7ec8\u4f7f\u7528 -delete \u4f5c\u4e3a\u6700\u540e\u4e00\u4e2a\u9009\u9879\uff0c\u5728\u5220\u9664\u4e4b\u524d\uff0c\u9996\u5148\u6d4b\u8bd5\u8be5\u547d\u4ee4\u800c\u4e0d\u4f7f\u7528\u8be5 -delete \u9009\u9879\u3002<\/p>\n

\r\n\/bin\/rm: Argument list too long\r\n<\/pre>\n

\u4f7f\u7528\u8be5 rm \u547d\u4ee4\u5220\u9664\u5305\u542b\u5927\u91cf\u6587\u4ef6\u7684\u76ee\u5f55\u65f6\uff0c\u4f1a\u51fa\u73b0\u6b64\u9519\u8bef\u6d88\u606f\u3002\u53d1\u751f\u8fd9\u79cd\u60c5\u51b5\u662f\u56e0\u4e3a\u6587\u4ef6\u6570\u5927\u4e8e\u547d\u4ee4\u884c\u53c2\u6570\u5927\u5c0f\u7684\u7cfb\u7edf\u9650\u5236\u3002<\/p>\n

\u8fd9\u4e2a\u95ee\u9898\u6709\u51e0\u79cd\u4e0d\u540c\u7684\u89e3\u51b3\u65b9\u6848\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5 cd \u624b\u52a8\u6216\u4f7f\u7528\u5faa\u73af\u9010\u4e2a\u5220\u9664\u5b50\u76ee\u5f55\u5230\u76ee\u5f55\u3002<\/p>\n

\u6700\u7b80\u5355\u7684\u89e3\u51b3\u65b9\u6848\u662f\u9996\u5148\u4f7f\u7528\u8be5 find \u547d\u4ee4\u5220\u9664\u76ee\u5f55\u4e2d\u7684\u6240\u6709\u6587\u4ef6\uff0c\u7136\u540e\u5220\u9664\u76ee\u5f55\uff1a<\/p>\n

\r\nfind \/dir -type f -delete && rm -r \/dir\r\n<\/pre>\n
\u603b\u7ed3<\/strong><\/div>\n

\u4f7f\u7528 rm \u548c find \u60a8\u53ef\u4ee5\u5feb\u901f\u6709\u6548\u5730\u5220\u9664\u57fa\u4e8e\u4e0d\u540c\u6807\u51c6\u7684\u76ee\u5f55\u3002<\/p>\n

\u5220\u9664\u76ee\u5f55\u662f\u4e00\u4e2a\u7b80\u5355\u800c\u7b80\u5355\u7684\u8fc7\u7a0b\uff0c\u4f46\u60a8\u5fc5\u987b\u5c0f\u5fc3\u4e0d\u8981\u5220\u9664\u91cd\u8981\u6570\u636e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 rmdir \uff0c rm \u548c find \u547d\u4ee4\u5220\u9664 Linux \u4e2d\u7684\u76ee\u5f55\u3002 \u5728\u4f60\u5f00 […]<\/p>\n","protected":false},"author":63,"featured_media":153504,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-153495","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/153495","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\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=153495"}],"version-history":[{"count":7,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/153495\/revisions"}],"predecessor-version":[{"id":157512,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/153495\/revisions\/157512"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/153504"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=153495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=153495"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=153495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}