How to alias cp with cp -i by default












8















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










share|improve this question




















  • 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
















8















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










share|improve this question




















  • 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














8












8








8








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










share|improve this question
















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







shell alias cp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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














  • 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










3 Answers
3






active

oldest

votes


















12














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.






share|improve this answer

































    2














    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



















    • 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














     alias cp="cp -i"


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






    share|improve this answer

























      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
      });


      }
      });














      draft saved

      draft discarded


















      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









      12














      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.






      share|improve this answer






























        12














        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.






        share|improve this answer




























          12












          12








          12







          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.






          share|improve this answer















          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.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 4 '14 at 6:41

























          answered Jun 7 '13 at 8:36









          AnthonAnthon

          60.6k17102165




          60.6k17102165

























              2














              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



















              • 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
















              2














              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



















              • 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














              2












              2








              2







              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













              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












              share|improve this answer



              share|improve this answer










              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














              • 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











              1














               alias cp="cp -i"


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






              share|improve this answer






























                1














                 alias cp="cp -i"


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






                share|improve this answer




























                  1












                  1








                  1







                   alias cp="cp -i"


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






                  share|improve this answer















                   alias cp="cp -i"


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







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jun 7 '13 at 22:18

























                  answered Jun 7 '13 at 8:37









                  michasmichas

                  15.2k33772




                  15.2k33772






























                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      Entries order in /etc/network/interfaces

                      新発田市

                      Grub takes very long (several minutes) to open Menu (in Multi-Boot-System)