How to alias cp with cp -i by default
Is there a good way to alias the command cp file1 file2 to cp -i file1 file2?
shell alias cp
add a comment |
Is there a good way to alias the command cp file1 file2 to cp -i file1 file2?
shell alias cp
3
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
add a comment |
Is there a good way to alias the command cp file1 file2 to cp -i file1 file2?
shell alias cp
Is there a good way to alias the command cp file1 file2 to cp -i file1 file2?
shell alias cp
shell alias cp
edited 2 hours ago
Rui F Ribeiro
39.6k1479132
39.6k1479132
asked Jun 7 '13 at 8:29
James ShapiroJames Shapiro
15326
15326
3
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
add a comment |
3
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
3
3
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
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
add a comment |
3 Answers
3
active
oldest
votes
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
fi
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.
add a comment |
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.
1
Someone who is a Unix novice is likely to be using a bash-like shell, but +1 for completeness' sake :)
– a CVn
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
add a comment |
alias cp="cp -i"
Put this line in your shell startup script. (probably ~/.bashrc)
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f78548%2fhow-to-alias-cp-with-cp-i-by-default%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
fi
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.
add a comment |
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
fi
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.
add a comment |
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
fi
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.
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
fi
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.
edited Mar 4 '14 at 6:41
answered Jun 7 '13 at 8:36
AnthonAnthon
60.6k17102165
60.6k17102165
add a comment |
add a comment |
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.
1
Someone who is a Unix novice is likely to be using a bash-like shell, but +1 for completeness' sake :)
– a CVn
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
add a comment |
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.
1
Someone who is a Unix novice is likely to be using a bash-like shell, but +1 for completeness' sake :)
– a CVn
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
add a comment |
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.
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.
answered Jun 7 '13 at 14:49
unxnutunxnut
3,6822919
3,6822919
1
Someone who is a Unix novice is likely to be using a bash-like shell, but +1 for completeness' sake :)
– a CVn
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
add a comment |
1
Someone who is a Unix novice is likely to be using a bash-like shell, but +1 for completeness' sake :)
– a CVn
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
1
1
Someone who is a Unix novice is likely to be using a bash-like shell, but +1 for completeness' sake :)
– a CVn
Jun 7 '13 at 17:38
Someone who is a Unix novice is likely to be using a bash-like shell, but +1 for completeness' sake :)
– a CVn
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
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
add a comment |
alias cp="cp -i"
Put this line in your shell startup script. (probably ~/.bashrc)
add a comment |
alias cp="cp -i"
Put this line in your shell startup script. (probably ~/.bashrc)
add a comment |
alias cp="cp -i"
Put this line in your shell startup script. (probably ~/.bashrc)
alias cp="cp -i"
Put this line in your shell startup script. (probably ~/.bashrc)
edited Jun 7 '13 at 22:18
answered Jun 7 '13 at 8:37
michasmichas
15.2k33772
15.2k33772
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f78548%2fhow-to-alias-cp-with-cp-i-by-default%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
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