Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

thanks

share|improve this question

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

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.

2 Answers 2

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:

#!/bin/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
3  
But you should in fact use a program like trash-cli instead of hacking rm. –  lgeorget Apr 30 '13 at 17:47
4  
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
1  
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.