Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I like to use rm but I often made mistakes so that I remove something mistakenly so I want to make somthing like mv .trash

so that

 rm file 

is equal to

 mv file ~/.trash

besides, I also want to periodically empty the ~/.trash folder then if I have made rm as mv, how to empty the ~/.trash folder


share|improve this question

marked as duplicate by Gilles, jasonwryan, vonbrand, Renan, slm May 2 '13 at 1:38

This question was marked as an exact duplicate of an existing question.

You'll want to use an alias. For example: alias rm 'mv \!* ~/.trash'

However, aliasing built-in commands can cause problems. So rather than aliasing rm, I'd call the alias del instead, that way your regular rm is still available to you.

share|improve this answer
can you explain \!* a bit? thanks – misteryes May 1 '13 at 18:46

Make a simple script called for example move_to_trash.sh:


mv "$@" ~/.trash

and then, add to your shell configuration file (for example, ~/.bashrc) :

alias rm <path to script>/move_to_trash.sh

To empty your trash periodically, you can configure a cronjob. Look at this tutorial for examples: http://www.ubuntututorials.com/use-crontab-ubuntu/.

share|improve this answer
But you should in fact use a program like trash-cli instead of hacking rm. – lgeorget Apr 30 '13 at 17:47
Using $* in a shell script is almost always wrong - it fails, it the filename contains whitespace or shell globbing characters. Use "$@" instead. – Uwe Apr 30 '13 at 18:06
oops, yes you're right. gonna edit that right now – lgeorget Apr 30 '13 at 19:49
Why do you suggest shadow-aliasing rm when you know it is not recommended? You should change your answer, and not put that in a comment (since it is important). I know you know it, but for the OP - @misteryes - check out this. – Emanuel Berg Apr 30 '13 at 22:25
I use "answer" to answer the question which is "How do I make rm file equal to mv file ~/.trash?" and "comment" to give additional information. Of course, this should not be done but from a technical point of view, it's possible and I show how. – lgeorget May 1 '13 at 0:04

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