1

When we do

mv /root/file /root/folder/

It moves /root/file to /root/folder

I want to do the same thing, but I want to reverse the order of how mv perceives the arguments

I want to declare an alias (not function) like

alias rm="mv /root/folder"

So, when I would do

rm /root/file

it would move that particular file to the /root/folder


Why, I don't want to use a function?

Because I cannot name the function rm() as the keyword rm already exists.

I want to be able to use the keyword rm because it's a regular habit for all of us.

2 Answers 2

6

Personally, I think this is a bad idea. If you want to use a trash or recycle bin on the command line, install trash-cli.

Why I think it is a bad idea:

  • What happens when you want to use rm - the exiting, remove files or directories application?

  • What happens when you move a file with a file name that matches a file already in /root/folder?


It's worth noting that the author of trash-cli also thinks this aliasing is a bad idea, after some experience with it:

Can I alias rm to trash-put?

You can but you shouldn't. In the early days I thought it was a good idea to do that but now I changed my mind.

...

And, Andrea recommends an alternative approach:

You could alias rm to something that will remind you to not use it:

alias rm='echo "This is not the command you are looking for."; false'
1
  • Another reason not to re-use rm is when you use other machines, you will assume it's the "safe recycle bin" version. Commented Jun 16, 2020 at 22:31
3

alias rm="mv -t /root/folder" will do that if you have a mv that supports the nonstandard -t option. See mv(1) for more options (you'll probably want --no-clobber / --interactive too).

If you want a POSIX solution, you can absolutely work around the basic rm (http://pubs.opengroup.org/onlinepubs/9699919799/utilities/rm.html#top) with a function named rm:

rm() {  mv "$@" /root/folder;  } # a start
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.