0

This question already has an answer here:

As all we know, this command is very danger, i have an idea as following, but i don't know how to accomplish. If you have best solution for it, welcome to write down.

I think we can create a directory to simulate trash, every time we delete something, those files/directories be moved to the trash, and there is a regular script, remind us of emptying trash.

marked as duplicate by edwinksl, Mark Kirby, karel, Eric Carvalho, Zanna Aug 19 '16 at 7:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    The dupe target will answer most of your question but does not provide the script for reminding you to empty trash. My personal opinion is you should just keep the trash for as long as you want until you need more HDD space, which is abundant these days and rarely a problem. This way, you basically use trash as a no-frills backup. – edwinksl Aug 13 '16 at 14:52
1

There are some tools, which you can use instead of rm, but nothing can change fact, that files removed are gone. I always use ls before rm to check if all files should be removed. Before using

rm ~/.cache/*

I will type:

ls ~/.cache/*
0

If you really want to stop yourself typing rm -fr ... you could alias out the command.

if you edit the file ~/.bashrc and include the following line in the alias section:

alias rm="rm --"

This means that every time you type the rm command, it gets substituted with rm --; the -- tells rm that you have finished entering options and everything after the -- should be treated as a file name. Therefore, once you have given the alias command, typing rm -f will cause the computer to execute rm -- -f, and, assuming that you have no file called "-f", you will get an error message along the lines of "rm: cannot remove '-f': No such file or directory"

If you are feeling really paranoid, you could use alias rm="rm -i --" instead. The -i asks rm to prompt before every delete.

Note that the alias will only apply to shells started after you have edited .bashrc, so don't type rm -fr / in an existing terming to see if its worked!

If you actually want to use any options with rm, you can avoid the alias by giving the command /bin/rm ...

Not the answer you're looking for? Browse other questions tagged or ask your own question.