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.
While you could use chmod to give only the root user execute permissions, this would likely create many problems on the system. A better choice would be to alias the command in your .bashrc file by adding the following line:
alias rm="rm -i"
This makes the command interactive and you will then be asked to confirm each deletion.
Thanks to other posters for pointing this out.
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
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.
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.
#!/bin/sh # 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).
PATH=~/bin:$PATH export PATH
You'll need to restart bash or use the command 'source .bash_profile' to bring your changes in to the current shell.
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.)