2

The command rm nukes files.

rm -i asks for confirmation before nuking the files.

When I use rm, I want rm -i to happen.

1
  • 2
    I used to work under a sysadmin who was a big fan of rm -i, so he added it as an alias on every server. The upshot was that I and everyone else working with him developed a practice of running rm -rf when emptying a directory rather than the safer rm -r, which will refuse to delete read-only files. You may think that rm -i makes you safer, but in my experience the opposite is the case.
    – Mikkel
    Jul 10, 2016 at 18:10

1 Answer 1

6

Use an Alias.

The alias command allows the user to launch any command or group of commands (including options and filenames) by entering a single word

alias rm="rm -i"

The next time you issue the command rm it will issue rm -i

You can also make a new alias in case you want to keep rm functioning as it does by default. To create a new alias

alias rmi="rm -i"

Now, rm will have it's default behavior and rmi will have the -i option

To make it permanent, just add it to your ~/.bash_profile. This way, everytime you open a new shell, your alias will be ready to go.

4
  • or you can unalias rm by prepending rm with a backward slash \rm and it follows the default behavior.
    – fd0
    Jul 10, 2016 at 13:01
  • 3
    fd0, Your comment, "or you can unalias rm by prepending rm with a \rm and it follows the default behavior." is not accurate. To unalias an alias you use unalias name, In a Terminal type help unalias. Now if one has named an alias the same as a binary executable and one wants to run the binary executable instead of the same named alias, then one can stop alias expansion by prepending a `\` backslash and in doing so one is not unalias-ing the alias, the alias still exists. Jul 10, 2016 at 13:34
  • @user3439894 Agree, I should have phrased it "you can temporarily unalias". BTW, help unalias returns an error message in my shell.
    – fd0
    Jul 10, 2016 at 14:33
  • @fd0, What shell are you using? unalias is a bash shell built-in and in OS X the default shell, help unalias returns: "unalias: unalias [-a] name [name ...] Remove NAMEs from the list of defined aliases. If the -a option is given, then remove all alias definitions." The key point here is using a "\" to stop alias expansion not unalias the alias, not even temporarily as it implies having to reset the alias. I know it somewhat antics with semantics however it's important to understand the difference between (temporarily) stoping alias expansion vs. unalias-ing the alias. Jul 10, 2016 at 14:59

You must log in to answer this question.

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