Copying a source directory using the command cp -rsf when target directory exists

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











up vote
-3
down vote

favorite












On Centos 7, when I use the command:



 cp -rsf /path/of/source /path/of/target


When the target directory exists, files would go to /path/of/target/source.



How can I avoid that?



EDIT:



  1. source and target are directories.

  2. Symlinks meet my environment needs. I need them to be symlink in order to save storage.

For example:



  1. mkdir /home/admin/test; mkdir /home/admin/test/1; touch /home/admin/test/1/1.txt;

  2. mkdir /home/admin/test2; mkdir /home/admin/test2/1; touch /home/admin/test2/1/1.txt;

  3. cp -rsf /home/admin/test/1 /home/admin/test2/1

  4. ls /home/admin/test2/1

result is:



drwxrwxr-x 2 admin admin 4096 Sep 16 15:57 1
-rw-rw-r-- 1 admin admin 0 Sep 16 15:56 1.txt



I wanted this result:



lrwxrwxrwx 1 admin admin 24 Sep 16 16:03 1.txt -> /home/admin/test/1/1.txt



It means the source directory itself is copied within the target, but I wanted its content to be copied (Just like when the target directory doesn't exist)










share|improve this question























  • how/why you want to copy from source to source?!!
    – TNT
    Sep 16 at 12:13










  • see the example. it's not source to source...
    – Ali Sh
    Sep 17 at 4:09














up vote
-3
down vote

favorite












On Centos 7, when I use the command:



 cp -rsf /path/of/source /path/of/target


When the target directory exists, files would go to /path/of/target/source.



How can I avoid that?



EDIT:



  1. source and target are directories.

  2. Symlinks meet my environment needs. I need them to be symlink in order to save storage.

For example:



  1. mkdir /home/admin/test; mkdir /home/admin/test/1; touch /home/admin/test/1/1.txt;

  2. mkdir /home/admin/test2; mkdir /home/admin/test2/1; touch /home/admin/test2/1/1.txt;

  3. cp -rsf /home/admin/test/1 /home/admin/test2/1

  4. ls /home/admin/test2/1

result is:



drwxrwxr-x 2 admin admin 4096 Sep 16 15:57 1
-rw-rw-r-- 1 admin admin 0 Sep 16 15:56 1.txt



I wanted this result:



lrwxrwxrwx 1 admin admin 24 Sep 16 16:03 1.txt -> /home/admin/test/1/1.txt



It means the source directory itself is copied within the target, but I wanted its content to be copied (Just like when the target directory doesn't exist)










share|improve this question























  • how/why you want to copy from source to source?!!
    – TNT
    Sep 16 at 12:13










  • see the example. it's not source to source...
    – Ali Sh
    Sep 17 at 4:09












up vote
-3
down vote

favorite









up vote
-3
down vote

favorite











On Centos 7, when I use the command:



 cp -rsf /path/of/source /path/of/target


When the target directory exists, files would go to /path/of/target/source.



How can I avoid that?



EDIT:



  1. source and target are directories.

  2. Symlinks meet my environment needs. I need them to be symlink in order to save storage.

For example:



  1. mkdir /home/admin/test; mkdir /home/admin/test/1; touch /home/admin/test/1/1.txt;

  2. mkdir /home/admin/test2; mkdir /home/admin/test2/1; touch /home/admin/test2/1/1.txt;

  3. cp -rsf /home/admin/test/1 /home/admin/test2/1

  4. ls /home/admin/test2/1

result is:



drwxrwxr-x 2 admin admin 4096 Sep 16 15:57 1
-rw-rw-r-- 1 admin admin 0 Sep 16 15:56 1.txt



I wanted this result:



lrwxrwxrwx 1 admin admin 24 Sep 16 16:03 1.txt -> /home/admin/test/1/1.txt



It means the source directory itself is copied within the target, but I wanted its content to be copied (Just like when the target directory doesn't exist)










share|improve this question















On Centos 7, when I use the command:



 cp -rsf /path/of/source /path/of/target


When the target directory exists, files would go to /path/of/target/source.



How can I avoid that?



EDIT:



  1. source and target are directories.

  2. Symlinks meet my environment needs. I need them to be symlink in order to save storage.

For example:



  1. mkdir /home/admin/test; mkdir /home/admin/test/1; touch /home/admin/test/1/1.txt;

  2. mkdir /home/admin/test2; mkdir /home/admin/test2/1; touch /home/admin/test2/1/1.txt;

  3. cp -rsf /home/admin/test/1 /home/admin/test2/1

  4. ls /home/admin/test2/1

result is:



drwxrwxr-x 2 admin admin 4096 Sep 16 15:57 1
-rw-rw-r-- 1 admin admin 0 Sep 16 15:56 1.txt



I wanted this result:



lrwxrwxrwx 1 admin admin 24 Sep 16 16:03 1.txt -> /home/admin/test/1/1.txt



It means the source directory itself is copied within the target, but I wanted its content to be copied (Just like when the target directory doesn't exist)







symlink cp recursive






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 16 at 11:40

























asked Sep 16 at 11:06









Ali Sh

12




12











  • how/why you want to copy from source to source?!!
    – TNT
    Sep 16 at 12:13










  • see the example. it's not source to source...
    – Ali Sh
    Sep 17 at 4:09
















  • how/why you want to copy from source to source?!!
    – TNT
    Sep 16 at 12:13










  • see the example. it's not source to source...
    – Ali Sh
    Sep 17 at 4:09















how/why you want to copy from source to source?!!
– TNT
Sep 16 at 12:13




how/why you want to copy from source to source?!!
– TNT
Sep 16 at 12:13












see the example. it's not source to source...
– Ali Sh
Sep 17 at 4:09




see the example. it's not source to source...
– Ali Sh
Sep 17 at 4:09










1 Answer
1






active

oldest

votes

















up vote
-3
down vote













The solution is to add -T
according to man



-T, --no-target-directory
treat DEST as a normal file



cp -rsfT /path/of/source /path/of/target


if the target directory exists it copies symlinks in it. The benefit is if there are other files in target, they remain untouched.






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%2f469364%2fcopying-a-source-directory-using-the-command-cp-rsf-when-target-directory-exist%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
    -3
    down vote













    The solution is to add -T
    according to man



    -T, --no-target-directory
    treat DEST as a normal file



    cp -rsfT /path/of/source /path/of/target


    if the target directory exists it copies symlinks in it. The benefit is if there are other files in target, they remain untouched.






    share|improve this answer


























      up vote
      -3
      down vote













      The solution is to add -T
      according to man



      -T, --no-target-directory
      treat DEST as a normal file



      cp -rsfT /path/of/source /path/of/target


      if the target directory exists it copies symlinks in it. The benefit is if there are other files in target, they remain untouched.






      share|improve this answer
























        up vote
        -3
        down vote










        up vote
        -3
        down vote









        The solution is to add -T
        according to man



        -T, --no-target-directory
        treat DEST as a normal file



        cp -rsfT /path/of/source /path/of/target


        if the target directory exists it copies symlinks in it. The benefit is if there are other files in target, they remain untouched.






        share|improve this answer














        The solution is to add -T
        according to man



        -T, --no-target-directory
        treat DEST as a normal file



        cp -rsfT /path/of/source /path/of/target


        if the target directory exists it copies symlinks in it. The benefit is if there are other files in target, they remain untouched.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Sep 16 at 12:05

























        answered Sep 16 at 11:48









        Ali Sh

        12




        12



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f469364%2fcopying-a-source-directory-using-the-command-cp-rsf-when-target-directory-exist%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)