Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to create an alias to move files and directories to the tmp directory. This is what I've tried:

alias rm='/bin/mv *.* /tmp'

The problem is that when I type rm filename, I get an error saying:

/bin/mv: target 'filename' is not a directory.

I know that filename is just a file. The point is that I want to move it to the specified /tmp directory. Can anyone help me?

share|improve this question
3  
As Flimzy noted, it is impossible to do it with alias. However, even if it were possible, it would be a bad idea to use alias. First, if you are used to custom behavior of rm , you might be forced to use normal edition on some other machine (false sense of security). Second, if some other user is using your computer, and tries to erase some big 10GB binary file to save space, he would really expect that the file is deleted, and not just moved to the /tmp. –  bbaja42 Jun 24 '11 at 19:40
1  
@bbaja42 has a valid point. Never go ahead and change the functionality of an essential built in command. –  slhck Jun 24 '11 at 19:43

2 Answers 2

Your alias means that when you type 'rm filename' you are really running this command:

/bin/mv *.* /tmp filename

That's obviously not what you want. I don't think you can use an alias for this, because I don't think there's a way to re-order the arguments passed to an alias. You'll be better off writing a short shell script that looks something like this:

#!/bin/sh
mv "$@" /tmp

Note: You don't want *.* either, that looks like a Windowsism... that will only match filenames with periods in them. Many file names in Linux don't contain periods.

share|improve this answer
1  
This will fail as soon as spaces are involved. "$@" is what you want. –  Daniel Beck Apr 16 '13 at 20:15
    
@DanielBeck: Thanks, updated. –  Flimzy Apr 17 '13 at 2:33
alias rm='mv -t /tmp ' 

using GNU Collection mv 8.13 on Ubuntu 12.04. Note the space after /tmp.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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