Topic
如何修改 rm 命令,让删除的文件去回收站
Tofloor
poster avatar
不避风云
deepin
2018-07-02 08:34
Author
非常不幸,输入过快,一下子让好几天的劳动成果成立泡影。想请问一下有没有大神,修改 rm 命令,让删除的文件去回收站,而不是直接删除。谢谢。

Reply Favorite View the author
All Replies
187******09
deepin
2018-07-02 08:59
#1
本帖最后由 i1516 于 2018-7-2 17:01 编辑
  1. sudo apt install trash-cli
Copy the Code
确保当前路径是:/home/user_name/   (user_name是你用户名)
然后修改.bashrc,加上:
  1. alias rm='trash-put'
Copy the Code

然后终端执行:
  1. source .bashrc
Copy the Code
然后就可以了

清空回收站是:
  1. trash-empty
Copy the Code
Reply View the author
小妖怪
deepin
2018-07-02 09:23
#2
补充一点,如果确认要删除文件,这样执行
  1. \rm file-to-delete
Copy the Code
\rm 可以让shell忽略别名
Reply View the author
ckurobac
deepin
2018-07-02 09:42
#3
我觉得还是……
Can I alias rm to trash-put?

You can but you shouldn't. In the early days I thought it was a good idea to do that but now I changed my mind.

Although the interface of trash-put seems to be compatible with rm, it has different semantics which will cause you problems. For example, while rm requires -R for deleting directories trash-put does not.
But sometimes I forget to use trash-put, really can't I?

You could alias rm to something that will remind you to not use it:

alias rm='echo "This is not the command you are looking for."; false'

Then, if you really want to use rm, simply prepend a slash to bypass the alias:

\rm file-without-hope

Note that Bash aliases are used only in interactive shells, so using this alias should not interfere with scripts that expect to use rm.
Reply View the author
小妖怪
deepin
2018-07-02 09:48
#4
很,还是直接用 trash-put 的好,如果嫌长,可以通过别名,整短点
Reply View the author
不避风云
deepin
2018-07-02 15:59
#5
https://bbs.deepin.org/post/159778
确保当前路径是:/home/user_name/   (user_name是你用户名)
然后修改.bashrc,加上:
然后终端执行:然后 ...

非常感谢。
Reply View the author
Daryl Xu
deepin
2018-07-03 05:52
#6
那还是用mv命令比较好
Reply View the author
小小怪下士
deepin
2020-06-23 14:46
#7
如果使用sudo的话,这个好像是会越过回收站的??
Reply View the author
Use Markdown Editor
Loading