Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

Is there a good way to alias the command cp file1 file2 to cp -i file1 file2?

Apologies if this is a dumb question, I'm a Unix novice.

share|improve this question
It's a great idea to alias destructive commands like cp, mv and rm - but don't depend on it... especially not as root! Because one day you'll be working at a computer without the alias you expect, and if you've then become used to the alias catching your mistakes, you'll be in for a rude awakening. – Baard Kopperud Jun 7 '13 at 13:41

You should put an alias in your start up script:

alias cp='cp -i'

You can put this directly in ~/.bashrc, but I have in my ~/.bashrc:

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases

and in ~/.bash_aliases I have:

alias realias='source ~/.bash_aliases'
alias cp='cp -i'
alias rm='rm -i'

and when I have added/changed things to that file I do realias (that does not remove aliases from the running shell you have taken out, for that use unalias).

If you do man bash and search for aliases you will not find examples but:

For almost every purpose, aliases are superseded by shell functions
The (`bash`) shell function alternative for the above alias is:

cp () { command cp -i "$@" ; }

shell functions are more powerful, but for simple things where aliases suffice.
I still tend to use them.

share|improve this answer

If you are using bash, the answers by Anthon and michas will work fine. However, if you are using csh or tcsh, the command to add will be

alias cp "cp -i"

and you will add it in your .cshrc file.

share|improve this answer
Someone who is a Unix novice is likely to be using a bash-like shell, but +1 for completeness' sake :) – Michael Kjörling Jun 7 '13 at 17:38
Thanks Michael. However, the novice works in whatever is given. And that depends mostly on the sys admins. Interestingly, on our campus, students get csh (not even tcsh) as their default shell working on Solaris. And since the original posting said Unix novice, I figured I should at least add my two cents worth. – unxnut Jun 7 '13 at 17:51
 alias cp="cp -i"

Put this line in your shell startup script. (probably ~/.bashrc)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.