6

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

0

2 Answers 2

2

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

5
  • 5
    But you should in fact use a program like trash-cli instead of hacking rm.
    – lgeorget
    Apr 30, 2013 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, 2013 at 18:06
  • oops, yes you're right. gonna edit that right now
    – lgeorget
    Apr 30, 2013 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. Apr 30, 2013 at 22:25
  • 2
    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, 2013 at 0:04
0

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.

2
  • can you explain \!* a bit? thanks
    – misteryes
    May 1, 2013 at 18:46
  • does not work for me on the \!* Sep 9, 2017 at 3:14

Not the answer you're looking for? Browse other questions tagged .