cp -Tr overwrite behavior

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
-1
down vote

favorite












I'm using GNU coreutils



I have a directory foo containing a file file1 and a directory bar containing file2.



If I now do a cp -rT foo bar, bar will contain both files instead of getting overwriten like the manpage might lead you to believe.



I'd like for ´bar´ only to contain the contents of ´foo´ and not get merged.










share|improve this question



















  • 1




    What part of the manual are you referring to? Is this using GNU cp from coreutils, or some other implementation of the cp command?
    – Kusalananda
    Sep 13 at 11:48











  • I'm referring to treat DEST as a normal file. Normal files get overwritten when you copy over them. This is not the case here.
    – Philippe
    Sep 13 at 11:58











  • the contents of the files are irrelevant. I'm talking about the contents of the directories
    – Philippe
    Sep 13 at 12:15














up vote
-1
down vote

favorite












I'm using GNU coreutils



I have a directory foo containing a file file1 and a directory bar containing file2.



If I now do a cp -rT foo bar, bar will contain both files instead of getting overwriten like the manpage might lead you to believe.



I'd like for ´bar´ only to contain the contents of ´foo´ and not get merged.










share|improve this question



















  • 1




    What part of the manual are you referring to? Is this using GNU cp from coreutils, or some other implementation of the cp command?
    – Kusalananda
    Sep 13 at 11:48











  • I'm referring to treat DEST as a normal file. Normal files get overwritten when you copy over them. This is not the case here.
    – Philippe
    Sep 13 at 11:58











  • the contents of the files are irrelevant. I'm talking about the contents of the directories
    – Philippe
    Sep 13 at 12:15












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I'm using GNU coreutils



I have a directory foo containing a file file1 and a directory bar containing file2.



If I now do a cp -rT foo bar, bar will contain both files instead of getting overwriten like the manpage might lead you to believe.



I'd like for ´bar´ only to contain the contents of ´foo´ and not get merged.










share|improve this question















I'm using GNU coreutils



I have a directory foo containing a file file1 and a directory bar containing file2.



If I now do a cp -rT foo bar, bar will contain both files instead of getting overwriten like the manpage might lead you to believe.



I'd like for ´bar´ only to contain the contents of ´foo´ and not get merged.







shell cp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 13 at 12:17

























asked Sep 13 at 11:17









Philippe

10514




10514







  • 1




    What part of the manual are you referring to? Is this using GNU cp from coreutils, or some other implementation of the cp command?
    – Kusalananda
    Sep 13 at 11:48











  • I'm referring to treat DEST as a normal file. Normal files get overwritten when you copy over them. This is not the case here.
    – Philippe
    Sep 13 at 11:58











  • the contents of the files are irrelevant. I'm talking about the contents of the directories
    – Philippe
    Sep 13 at 12:15












  • 1




    What part of the manual are you referring to? Is this using GNU cp from coreutils, or some other implementation of the cp command?
    – Kusalananda
    Sep 13 at 11:48











  • I'm referring to treat DEST as a normal file. Normal files get overwritten when you copy over them. This is not the case here.
    – Philippe
    Sep 13 at 11:58











  • the contents of the files are irrelevant. I'm talking about the contents of the directories
    – Philippe
    Sep 13 at 12:15







1




1




What part of the manual are you referring to? Is this using GNU cp from coreutils, or some other implementation of the cp command?
– Kusalananda
Sep 13 at 11:48





What part of the manual are you referring to? Is this using GNU cp from coreutils, or some other implementation of the cp command?
– Kusalananda
Sep 13 at 11:48













I'm referring to treat DEST as a normal file. Normal files get overwritten when you copy over them. This is not the case here.
– Philippe
Sep 13 at 11:58





I'm referring to treat DEST as a normal file. Normal files get overwritten when you copy over them. This is not the case here.
– Philippe
Sep 13 at 11:58













the contents of the files are irrelevant. I'm talking about the contents of the directories
– Philippe
Sep 13 at 12:15




the contents of the files are irrelevant. I'm talking about the contents of the directories
– Philippe
Sep 13 at 12:15










1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










With GNU cp, the -T option is used to ensure that the source directory will not be put inside the target directory. It will not cause to contents of the target directory to be removed.



The info documentation on this (info '(coreutils)Target directory') says (it's using mv as an example):




-T



--no-target-directory



Do not treat the last operand specially when it is a directory or a
symbolic link to a directory. This can help avoid race conditions
in programs that operate in a shared area. For example, when the
command mv /tmp/source /tmp/dest succeeds, there is no guarantee
that /tmp/source was renamed to /tmp/dest: it could have been
renamed to /tmp/dest/source instead, if some other process
created /tmp/dest as a directory. However, if mv -T /tmp/source /tmp/dest succeeds, there is no question that /tmp/source was
renamed to /tmp/dest.




Note that mv -T source dest will fail if dest is not empty.




To replace the contents of bar with that of foo in your example, use



rm -rf bar
cp -r foo bar


or,



rsync --archive --delete foo/ bar





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',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    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%2f468767%2fcp-tr-overwrite-behavior%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    With GNU cp, the -T option is used to ensure that the source directory will not be put inside the target directory. It will not cause to contents of the target directory to be removed.



    The info documentation on this (info '(coreutils)Target directory') says (it's using mv as an example):




    -T



    --no-target-directory



    Do not treat the last operand specially when it is a directory or a
    symbolic link to a directory. This can help avoid race conditions
    in programs that operate in a shared area. For example, when the
    command mv /tmp/source /tmp/dest succeeds, there is no guarantee
    that /tmp/source was renamed to /tmp/dest: it could have been
    renamed to /tmp/dest/source instead, if some other process
    created /tmp/dest as a directory. However, if mv -T /tmp/source /tmp/dest succeeds, there is no question that /tmp/source was
    renamed to /tmp/dest.




    Note that mv -T source dest will fail if dest is not empty.




    To replace the contents of bar with that of foo in your example, use



    rm -rf bar
    cp -r foo bar


    or,



    rsync --archive --delete foo/ bar





    share|improve this answer
























      up vote
      1
      down vote



      accepted










      With GNU cp, the -T option is used to ensure that the source directory will not be put inside the target directory. It will not cause to contents of the target directory to be removed.



      The info documentation on this (info '(coreutils)Target directory') says (it's using mv as an example):




      -T



      --no-target-directory



      Do not treat the last operand specially when it is a directory or a
      symbolic link to a directory. This can help avoid race conditions
      in programs that operate in a shared area. For example, when the
      command mv /tmp/source /tmp/dest succeeds, there is no guarantee
      that /tmp/source was renamed to /tmp/dest: it could have been
      renamed to /tmp/dest/source instead, if some other process
      created /tmp/dest as a directory. However, if mv -T /tmp/source /tmp/dest succeeds, there is no question that /tmp/source was
      renamed to /tmp/dest.




      Note that mv -T source dest will fail if dest is not empty.




      To replace the contents of bar with that of foo in your example, use



      rm -rf bar
      cp -r foo bar


      or,



      rsync --archive --delete foo/ bar





      share|improve this answer






















        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        With GNU cp, the -T option is used to ensure that the source directory will not be put inside the target directory. It will not cause to contents of the target directory to be removed.



        The info documentation on this (info '(coreutils)Target directory') says (it's using mv as an example):




        -T



        --no-target-directory



        Do not treat the last operand specially when it is a directory or a
        symbolic link to a directory. This can help avoid race conditions
        in programs that operate in a shared area. For example, when the
        command mv /tmp/source /tmp/dest succeeds, there is no guarantee
        that /tmp/source was renamed to /tmp/dest: it could have been
        renamed to /tmp/dest/source instead, if some other process
        created /tmp/dest as a directory. However, if mv -T /tmp/source /tmp/dest succeeds, there is no question that /tmp/source was
        renamed to /tmp/dest.




        Note that mv -T source dest will fail if dest is not empty.




        To replace the contents of bar with that of foo in your example, use



        rm -rf bar
        cp -r foo bar


        or,



        rsync --archive --delete foo/ bar





        share|improve this answer












        With GNU cp, the -T option is used to ensure that the source directory will not be put inside the target directory. It will not cause to contents of the target directory to be removed.



        The info documentation on this (info '(coreutils)Target directory') says (it's using mv as an example):




        -T



        --no-target-directory



        Do not treat the last operand specially when it is a directory or a
        symbolic link to a directory. This can help avoid race conditions
        in programs that operate in a shared area. For example, when the
        command mv /tmp/source /tmp/dest succeeds, there is no guarantee
        that /tmp/source was renamed to /tmp/dest: it could have been
        renamed to /tmp/dest/source instead, if some other process
        created /tmp/dest as a directory. However, if mv -T /tmp/source /tmp/dest succeeds, there is no question that /tmp/source was
        renamed to /tmp/dest.




        Note that mv -T source dest will fail if dest is not empty.




        To replace the contents of bar with that of foo in your example, use



        rm -rf bar
        cp -r foo bar


        or,



        rsync --archive --delete foo/ bar






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Sep 13 at 12:18









        Kusalananda

        107k14209331




        107k14209331



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f468767%2fcp-tr-overwrite-behavior%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay