{"id":97132,"date":"2024-06-05T03:13:12","date_gmt":"2024-06-04T19:13:12","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=97132"},"modified":"2024-06-05T03:13:12","modified_gmt":"2024-06-04T19:13:12","slug":"rm-saferm-trash","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/rm-saferm-trash.html","title":{"rendered":"\u5982\u4f55\u7528 “rm” \u547d\u4ee4\u628a\u6587\u4ef6\u4e22\u5230 “\u5783\u573e\u6876”"},"content":{"rendered":"

\u4eba\u7c7b\u72af\u9519\u8bef\u662f\u56e0\u4e3a\u6211\u4eec\u4e0d\u662f\u4e00\u4e2a\u53ef\u7f16\u7a0b\u8bbe\u5907\uff0c\u6240\u4ee5\uff0c\u5728\u4f7f\u7528 rm<\/span> \u547d\u4ee4\u65f6\u8981\u989d\u5916\u6ce8\u610f\uff0c\u4e0d\u8981\u5728\u4efb\u4f55\u65f6\u5019\u4f7f\u7528 rm -rf *<\/span>\u3002\u5f53\u4f60\u4f7f\u7528 rm<\/span> \u547d\u4ee4\u65f6\uff0c\u5b83\u4f1a\u6c38\u4e45\u5220\u9664\u6587\u4ef6\uff0c\u4e0d\u4f1a\u50cf\u6587\u4ef6\u7ba1\u7406\u5668\u90a3\u6837\u5c06\u8fd9\u4e9b\u6587\u4ef6\u79fb\u52a8\u5230 \u201c\u5783\u573e\u7bb1\u201d\u3002<\/p>\n

\"\"<\/p>\n

\u6709\u65f6\u6211\u4eec\u4f1a\u5c06\u4e0d\u5e94\u8be5\u5220\u9664\u7684\u6587\u4ef6\u5220\u9664\u6389\uff0c\u6240\u4ee5\u5f53\u9519\u8bef\u5730\u5220\u9664\u4e86\u6587\u4ef6\u65f6\u8be5\u600e\u4e48\u529e\uff1f \u4f60\u5fc5\u987b\u770b\u770b\u6062\u590d\u5de5\u5177\uff08Linux \u4e2d\u6709\u5f88\u591a\u6570\u636e\u6062\u590d\u5de5\u5177\uff09\uff0c\u4f46\u6211\u4eec\u4e0d\u77e5\u9053\u662f\u5426\u80fd\u5c06\u5b83\u767e\u5206\u4e4b\u767e\u6062\u590d\uff0c\u6240\u4ee5\u8981\u5982\u4f55\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff1f<\/p>\n

\u6211\u4eec\u6700\u8fd1\u53d1\u8868\u4e86\u4e00\u7bc7\u5173\u4e8e Trash-Cli<\/a>\u7684\u6587\u7ae0\uff0c\u5728\u8bc4\u8bba\u90e8\u5206\uff0c\u6211\u4eec\u4ece\u7528\u6237 Eemil Lgz \u90a3\u91cc\u83b7\u5f97\u4e86\u4e00\u4e2a\u5173\u4e8e saferm.sh<\/a>\u00a0\u811a\u672c\u7684\u66f4\u65b0\uff0c\u5b83\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5c06\u6587\u4ef6\u79fb\u52a8\u5230\u201c\u5783\u573e\u7bb1\u201d\u800c\u4e0d\u662f\u6c38\u4e45\u5220\u9664\u5b83\u4eec\u3002<\/p>\n

\u5c06\u6587\u4ef6\u79fb\u52a8\u5230\u201c\u5783\u573e\u6876\u201d\u662f\u4e00\u4e2a\u597d\u4e3b\u610f\uff0c\u5f53\u4f60\u65e0\u610f\u4e2d\u8fd0\u884c rm<\/span> \u547d\u4ee4\u65f6\uff0c\u53ef\u4ee5\u62ef\u6551\u4f60\uff1b\u4f46\u662f\u5f88\u5c11\u6709\u4eba\u4f1a\u8bf4\u8fd9\u662f\u4e00\u4e2a\u574f\u4e60\u60ef\uff0c\u5982\u679c\u4f60\u4e0d\u6ce8\u610f\u201c\u5783\u573e\u6876\u201d\uff0c\u5b83\u53ef\u80fd\u4f1a\u5728\u4e00\u5b9a\u7684\u65f6\u95f4\u5185\u88ab\u6587\u4ef6\u548c\u6587\u4ef6\u5939\u5806\u79ef\u8d77\u6765\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u5efa\u8bae\u4f60\u6309\u7167\u4f60\u7684\u610f\u613f\u53bb\u505a\u4e00\u4e2a\u5b9a\u65f6\u4efb\u52a1\u3002<\/p>\n

\u8fd9\u9002\u7528\u4e8e\u670d\u52a1\u5668\u548c\u684c\u9762\u4e24\u79cd\u73af\u5883\u3002 \u5982\u679c\u811a\u672c\u68c0\u6d4b\u5230 GNOME \u3001KDE\u3001Unity \u6216 LXDE \u684c\u9762\u73af\u5883\uff08DE\uff09\uff0c\u5219\u5b83\u5c06\u6587\u4ef6\u6216\u6587\u4ef6\u5939\u5b89\u5168\u5730\u79fb\u52a8\u5230\u9ed8\u8ba4\u5783\u573e\u7bb1 $HOME\/.local\/share\/Trash\/files<\/span>\uff0c\u5426\u5219\u4f1a\u5728\u60a8\u7684\u4e3b\u76ee\u5f55\u4e2d\u521b\u5efa\u5783\u573e\u7bb1\u6587\u4ef6\u5939 $HOME\/Trash<\/span>\u3002<\/p>\n

saferm.sh<\/span> \u811a\u672c\u6258\u7ba1\u5728 Github \u4e2d\uff0c\u53ef\u4ee5\u4ece\u4ed3\u5e93\u4e2d\u514b\u9686\uff0c\u4e5f\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a saferm.sh<\/span> \u7684\u6587\u4ef6\u5e76\u590d\u5236\u5176\u4e0a\u7684\u4ee3\u7801\u3002<\/p>\n

$ git clone https:\/\/github.com\/lagerspetz\/linux-stuff\r\n$ sudo mv linux-stuff\/scripts\/saferm.sh \/bin\r\n$ rm -Rf linux-stuff\r\n<\/pre>\n

\u5728 .bashrc<\/span> \u6587\u4ef6\u4e2d\u8bbe\u7f6e\u522b\u540d\uff0c<\/p>\n

alias rm=saferm.sh\r\n<\/pre>\n

\u6267\u884c\u4e0b\u9762\u7684\u547d\u4ee4\u4f7f\u5176\u751f\u6548\uff0c<\/p>\n

$ source ~\/.bashrc\r\n<\/pre>\n

\u4e00\u5207\u5c31\u7eea\uff0c\u73b0\u5728\u4f60\u53ef\u4ee5\u6267\u884c rm<\/span> \u547d\u4ee4\uff0c\u81ea\u52a8\u5c06\u6587\u4ef6\u79fb\u52a8\u5230\u201d\u5783\u573e\u6876\u201d\uff0c\u800c\u4e0d\u662f\u6c38\u4e45\u5220\u9664\u5b83\u4eec\u3002<\/p>\n

\u6d4b\u8bd5\u4e00\u4e0b\uff0c\u6211\u4eec\u5c06\u5220\u9664\u4e00\u4e2a\u540d\u4e3a magi.txt<\/span> \u7684\u6587\u4ef6\uff0c\u547d\u4ee4\u884c\u660e\u786e\u7684\u63d0\u9192\u4e86 Moving magi.txt to $HOME\/.local\/share\/Trash\/file<\/span>\u3002<\/p>\n

$ rm -rf magi.txt\r\nMoving magi.txt to \/home\/magi\/.local\/share\/Trash\/files\r\n<\/pre>\n

\u4e5f\u53ef\u4ee5\u901a\u8fc7 ls<\/span> \u547d\u4ee4\u6216 trash-cli<\/span> \u8fdb\u884c\u9a8c\u8bc1\u3002<\/p>\n

$ ls -lh \/home\/magi\/.local\/share\/Trash\/files\r\nPermissions Size User Date Modified Name\r\n.rw-r--r-- 32 magi 11 Oct 16:24 magi.txt    \r\n<\/pre>\n

\u6216\u8005\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6587\u4ef6\u7ba1\u7406\u5668\u754c\u9762\u4e2d\u67e5\u770b\u76f8\u540c\u7684\u5185\u5bb9\u3002<\/p>\n

\"\"<\/p>\n

\u8981\u4e86\u89e3 saferm.sh<\/span> \u7684\u5176\u4ed6\u9009\u9879\uff0c\u8bf7\u67e5\u770b\u5e2e\u52a9\u3002<\/p>\n

$ saferm.sh -h\r\nThis is saferm.sh 1.16. LXDE and Gnome3 detection.\r\nWill ask to unsafe-delete instead of cross-fs move. Allows unsafe (regular rm) delete (ignores trashinfo).\r\nCreates trash and trashinfo directories if they do not exist. Handles symbolic link deletion.\r\nDoes not complain about different user any more.\r\n\r\nUsage: \/path\/to\/saferm.sh [OPTIONS] [--] files and dirs to safely remove\r\nOPTIONS:\r\n-r      allows recursively removing directories.\r\n-f      Allow deleting special files (devices, ...).\r\n-u      Unsafe mode, bypass trash and delete files permanently.\r\n-v      Verbose, prints more messages. Default in this version.\r\n-q      Quiet mode. Opposite of verbose.\r\n\r\n<\/pre>\n
\n

via: https:\/\/www.2daygeek.com\/rm-command-to-move-files-to-trash-can-rm-alias\/<\/a><\/p>\n

\u4f5c\u8005\uff1a2DAYGEEK<\/a>[3]<\/span> \u8bd1\u8005\uff1aamwps290<\/a>[4]<\/span> \u6821\u5bf9\uff1awxy<\/a>[5]<\/span><\/p>\n

\u672c\u6587\u7531 LCTT<\/a>[6]<\/span> \u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd<\/a>[7]<\/span> \u8363\u8a89\u63a8\u51fa<\/p>\n

\n

\u539f\u6587\u6765\u81ea\uff1ahttps:\/\/linux.cn\/article-9425-1.html<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1ahttps:\/\/lrxjmw.cn\/rm-saferm-trash.html<\/a>\u7f16\u8f91\uff1a\u9004\u589e\u5b9d\uff0c\u5ba1\u6838\u5458\uff1a\u5218\u9044<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u4eba\u7c7b\u72af\u9519\u8bef\u662f\u56e0\u4e3a\u6211\u4eec\u4e0d\u662f\u4e00\u4e2a\u53ef\u7f16\u7a0b\u8bbe\u5907\uff0c\u6240\u4ee5\uff0c\u5728\u4f7f\u7528 rm \u547d\u4ee4\u65f6\u8981\u989d\u5916\u6ce8\u610f\uff0c\u4e0d\u8981\u5728\u4efb\u4f55\u65f6\u5019\u4f7f\u7528 rm -rf […]<\/p>\n","protected":false},"author":309,"featured_media":97133,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-97132","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\/97132","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\/309"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=97132"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/97132\/revisions"}],"predecessor-version":[{"id":97140,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/97132\/revisions\/97140"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/97133"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=97132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=97132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=97132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}