1

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.

2 Answers2

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/*
iacobus
  • 514
1

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 ...

Nick Sillito
  • 1,636