Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I often misuse "rm" for "mv"! I hope to make "rm" a command requiring root privilege, like "apt-get". How to do that, please? My system is Ubuntu 10.10.

share|improve this question

migrated from Feb 16 '12 at 9:03

This question came from our site for professional and enthusiast programmers.

This is off-topic for StackOverflow. It should be asked on or – Brian Roach Feb 16 '12 at 7:40
Create a shell alias for rm: 'rm -i' – Brett Hale Feb 16 '12 at 8:17
You could also alias rm to be "sudo rm" – Richard Holloway Feb 16 '12 at 9:18
It's not the answer you want, but you should take care and think before pressing enter, especially around dangerous commands like rm – CJBrew Feb 16 '12 at 9:34
I agree with @CJBrew. And i think if you keep typing rm when you mean mv, and don't have backups or a versioning system ( or at least a recycle bin or something (, you kind of deserve to lose files. – Christoffer Hammarström Feb 16 '12 at 16:15
up vote -5 down vote accepted

change to your root user. Then run:

chmod 700 /bin/rm

It should already be owned by root:root.

share|improve this answer
Exactly it is ! – updogliu Feb 16 '12 at 7:44
-1 This approach will wreck any system command which invokes /bin/rm behind the scenes (basically any shell script which uses temporary files, among others)! Go with the alias instead. – tripleee Feb 16 '12 at 9:01
This is likely to break things. – Richard Holloway Feb 16 '12 at 9:17
rm needs to be usable by applications which created their own files, are owned by them and shouldn't need root priveleges to remove them. Use rm -i – deed02392 Feb 16 '12 at 10:12
Yes, doing this will break the system. Someone should unaccept this answer. – Christoffer Hammarström Feb 16 '12 at 14:35

The best solution is to use rm -i

share|improve this answer

Definitely aliasing the interactive version of rm is the best solution, because you wouldn't want normal scripts to break when rm suddenly starts to behave differently. Just add alias rm="rm -i" to your ~/.bashrc and you'll get a question like rm: remove regular file 'filename'?, which you'll have to answer with y [ENTER] or n [ENTER].

I think it is better that aliasing sudo rm, because you are explicitly told which files are to be deleted, while with sudo you're only asked for a password like on dozen other occasions and before you know it you will approve the command sudo rm *. The command rm -i protects you from such (and less obvious) too greedy wildcard matches, because it asks you about every single file.

share|improve this answer

How about alias rm to 'sudo rm'? Every time you need to enter the password.

share|improve this answer
You hardly want to run rm with escalated privileges. I would go for something like alias rm='sudo true && /bin/rm’ or just the good old rm -i. With sudo you get to run without the password for a while, whereas rm -i will always prompt. – tripleee Feb 16 '12 at 10:08
Thanks you for your comment! – efan Feb 19 '12 at 8:23

You could alias rm to something like echo 'Do you really want to remove this?'

This will prevent you from using rm.

Then, if you really want to remove something you will need to type /bin/rm (to bypass the alias).

share|improve this answer

This is off the top of my head. I'm sure folks will correct edit if I have my syntax off or something.

Insert this script in your ~/bin and call it rm.


# Run /bin/rm using all the arguments from the command line
/bin/rm $@

Make sure that ~/bin is first in your $PATH so your rm is found before /bin/rm.

Set that script to ownership root:your_group and permissions 760 so that you must sudo in order to execute rm and you will not need to be root to write or read the file. You can then also get around this script by simply using /bin/rm instead of rm, but you'll do that knowingly. Maybe you'll even get in the habit of specifying rm by absolute path and eventually will do without the little extra script.

If you aren't familiar with setting your own path variable, edit your .bash_profile with these lines (or edit if they already exist).

export PATH

You'll need to restart bash or use the command 'source .bash_profile' to bring your changes in to the current shell.

(Of course, rm -i is much simpler and less breaky than chmoding rm itself, but this answers the question as asked without breaking anything that isn't run by the user who already knows of the limitation.)

share|improve this answer

You must log in to answer this question.

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