I was trying to change a file name in the Mac OS X terminal the other day using the ‘mv’ command.
Instead, I deleted the file by accidentally entering the ‘rm’ command.
$ rm my_file.py another_name_for_my_file.py
rm: another_name_for_my_file.py: No such file or directory
I know I should have been more careful before pressing the <Enter> key, and I do try, but sometimes my fingers just get confused with the ‘rm’ and ‘mv’ commands.
So, I would like to know the way to change the name of the ‘rm’ command to another, e.g., ‘remove’, to prevent further accidents, but can’t find any directions on the web. (I am presuming this may be possible by editing a ~/.bashrc or ~/.profile file.)
Does a bypass exist? Or is there no way to change a terminal command?
You can add an
aliasfor any command. You could use this to disablerm, but a better option is to make sure thatrmalways asks for confirmation, which is the behavior of the-iflag.Add the following line to your .bashrc:
Then open a new terminal window, or type
source .bashrcin an open terminal window. Now when you typerm, it will ask you if you’re sure. Override this by passing the-fflag to your alias:rm -f.