Reputation: 16422
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?
Upvotes: 1
Views: 1569
Reputation: 59617
You can add an alias
for any command. You could use this to disable rm
, but a better option is to make sure that rm
always asks for confirmation, which is the behavior of the -i
flag.
-i Request confirmation before attempting to remove each file, regardless of the file's permissions, or whether or not the standard input device is a terminal. The -i option overrides any previous -f options.
Add the following line to your .bashrc:
alias rm='rm -i'
Then open a new terminal window, or type source .bashrc
in an open terminal window. Now when you type rm
, it will ask you if you're sure. Override this by passing the -f
flag to your alias: rm -f
.
Upvotes: 3