Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Let's Sekuhara!

macrumors 6502
Original poster
Jun 30, 2008
357
1
日本
Hi, I'm new to UNIX and want to set up an alias called "trash" that will send files to ~/.Trash instead of deleting them like rm does.

I've found multiple websites stating that a command such as:
Code:
alias trash 'mv\!* ~/.Trash'
will do just that.

However when I run that command all I get is:
Code:
-bash: alias: mv\!* ~/.Trash: not found

Why? :confused:
 
Ah ha!
Thank you for shedding light on that.
Nothing I can do to work around that I suppose?

Yes, you can create a function that you define in your ~/.profile that takes the arguments, then make the alias call that function, I have never done that my self though.

But, to be honest it may be more straight forward to just create a small script that does what you want. This should do what that alias did, you can do more here as well if you want to, like suppress the error from "mv" and replace it with a custom error message if a file can't be found and so on.

Test and run at your own risk. :)

Code:
#!/bin/bash
#

if [ $# -lt 1 ]
then
    echo "Usage: trash [filename]"
    exit 0
fi
    for i in "$@"
    do
        mv "$i" ~/.Trash
    done

If you have folder in your $PATH where you place your scripts, just put it there, after you 'chmod u+x' it.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.