How can I copy a directory structure but ignore symlinks?












1















I have a software project that uses a specific directory structure for configuration files. Symlinks are used to point to the config files currently in use. I'm in the process of making a custom installer script for CentOS 7.



I use another script to bundle the directory structure and the installer script. The bundle script uses rsync to copy the directory structure with all default symlinks intact. It also excludes the hidden svn folders.



rsync -a --exclude=".*" [sourceFolder] [bundleFolder]


The install script uses cp to install the directory structure (default symlinks intact) to the user specified location.



cp -rP [bundleFolder] [installLocation]


This all works great.



However, I also need the installer script to be able to update an existing installation. The problem with this is that I need to be able to update the config files without altering the symlinks that the user has in place.



Is there a way to copy the entire directory structure (all folders and sub-folders) but ignore any symlinks? I'm trying to avoid having to use find to parse the entire structure in a bash script just to ignore the symlinks. I assumed that this would be a common task that cp or rsync would have an option for. I haven't been able to find one though.










share|improve this question

























  • I would recommend man rsync and reading the options that pertain to links. Specifically, the --safe-links flag: "This tells rsync to ignore any symbolic links which point outside the copied tree." Or, perhaps the --no-OPTION option that enables you to do things like --no-links

    – h3rrmiller
    Sep 14 '17 at 15:18













  • I read about the --safe-links flag but that one didn't work for my scenario. Apparently I missed the --no-links option though. It does exactly what I need.

    – Blackwood
    Sep 14 '17 at 15:52











  • It's an easy one to miss since it's --no-OPTION to omit whatever OPTION is

    – h3rrmiller
    Sep 14 '17 at 16:29











  • What if the user customized the symlinks and config file contents? Updating an installation to a new version while preserving local config customization isn't something you can just whip up with some rsync/tar/cpio/find combo.

    – Kaz
    Sep 15 '17 at 3:30













  • Updating the config files should be rare (only when additional settings are added). However, the way the software handles the config files is a bit more complicated than I explained in the original post. It uses inotify to monitor for changes in the config files. If an updated config file contains different values than what the user originally had, the software will detect that and give the user the option to restore their previous settings in the updated config file. The installer script is just to automate the process that I had already been doing manually.

    – Blackwood
    Sep 18 '17 at 14:49


















1















I have a software project that uses a specific directory structure for configuration files. Symlinks are used to point to the config files currently in use. I'm in the process of making a custom installer script for CentOS 7.



I use another script to bundle the directory structure and the installer script. The bundle script uses rsync to copy the directory structure with all default symlinks intact. It also excludes the hidden svn folders.



rsync -a --exclude=".*" [sourceFolder] [bundleFolder]


The install script uses cp to install the directory structure (default symlinks intact) to the user specified location.



cp -rP [bundleFolder] [installLocation]


This all works great.



However, I also need the installer script to be able to update an existing installation. The problem with this is that I need to be able to update the config files without altering the symlinks that the user has in place.



Is there a way to copy the entire directory structure (all folders and sub-folders) but ignore any symlinks? I'm trying to avoid having to use find to parse the entire structure in a bash script just to ignore the symlinks. I assumed that this would be a common task that cp or rsync would have an option for. I haven't been able to find one though.










share|improve this question

























  • I would recommend man rsync and reading the options that pertain to links. Specifically, the --safe-links flag: "This tells rsync to ignore any symbolic links which point outside the copied tree." Or, perhaps the --no-OPTION option that enables you to do things like --no-links

    – h3rrmiller
    Sep 14 '17 at 15:18













  • I read about the --safe-links flag but that one didn't work for my scenario. Apparently I missed the --no-links option though. It does exactly what I need.

    – Blackwood
    Sep 14 '17 at 15:52











  • It's an easy one to miss since it's --no-OPTION to omit whatever OPTION is

    – h3rrmiller
    Sep 14 '17 at 16:29











  • What if the user customized the symlinks and config file contents? Updating an installation to a new version while preserving local config customization isn't something you can just whip up with some rsync/tar/cpio/find combo.

    – Kaz
    Sep 15 '17 at 3:30













  • Updating the config files should be rare (only when additional settings are added). However, the way the software handles the config files is a bit more complicated than I explained in the original post. It uses inotify to monitor for changes in the config files. If an updated config file contains different values than what the user originally had, the software will detect that and give the user the option to restore their previous settings in the updated config file. The installer script is just to automate the process that I had already been doing manually.

    – Blackwood
    Sep 18 '17 at 14:49
















1












1








1








I have a software project that uses a specific directory structure for configuration files. Symlinks are used to point to the config files currently in use. I'm in the process of making a custom installer script for CentOS 7.



I use another script to bundle the directory structure and the installer script. The bundle script uses rsync to copy the directory structure with all default symlinks intact. It also excludes the hidden svn folders.



rsync -a --exclude=".*" [sourceFolder] [bundleFolder]


The install script uses cp to install the directory structure (default symlinks intact) to the user specified location.



cp -rP [bundleFolder] [installLocation]


This all works great.



However, I also need the installer script to be able to update an existing installation. The problem with this is that I need to be able to update the config files without altering the symlinks that the user has in place.



Is there a way to copy the entire directory structure (all folders and sub-folders) but ignore any symlinks? I'm trying to avoid having to use find to parse the entire structure in a bash script just to ignore the symlinks. I assumed that this would be a common task that cp or rsync would have an option for. I haven't been able to find one though.










share|improve this question
















I have a software project that uses a specific directory structure for configuration files. Symlinks are used to point to the config files currently in use. I'm in the process of making a custom installer script for CentOS 7.



I use another script to bundle the directory structure and the installer script. The bundle script uses rsync to copy the directory structure with all default symlinks intact. It also excludes the hidden svn folders.



rsync -a --exclude=".*" [sourceFolder] [bundleFolder]


The install script uses cp to install the directory structure (default symlinks intact) to the user specified location.



cp -rP [bundleFolder] [installLocation]


This all works great.



However, I also need the installer script to be able to update an existing installation. The problem with this is that I need to be able to update the config files without altering the symlinks that the user has in place.



Is there a way to copy the entire directory structure (all folders and sub-folders) but ignore any symlinks? I'm trying to avoid having to use find to parse the entire structure in a bash script just to ignore the symlinks. I assumed that this would be a common task that cp or rsync would have an option for. I haven't been able to find one though.







bash shell-script shell






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 18 '17 at 17:26









roaima

44.2k555119




44.2k555119










asked Sep 14 '17 at 15:12









BlackwoodBlackwood

136




136













  • I would recommend man rsync and reading the options that pertain to links. Specifically, the --safe-links flag: "This tells rsync to ignore any symbolic links which point outside the copied tree." Or, perhaps the --no-OPTION option that enables you to do things like --no-links

    – h3rrmiller
    Sep 14 '17 at 15:18













  • I read about the --safe-links flag but that one didn't work for my scenario. Apparently I missed the --no-links option though. It does exactly what I need.

    – Blackwood
    Sep 14 '17 at 15:52











  • It's an easy one to miss since it's --no-OPTION to omit whatever OPTION is

    – h3rrmiller
    Sep 14 '17 at 16:29











  • What if the user customized the symlinks and config file contents? Updating an installation to a new version while preserving local config customization isn't something you can just whip up with some rsync/tar/cpio/find combo.

    – Kaz
    Sep 15 '17 at 3:30













  • Updating the config files should be rare (only when additional settings are added). However, the way the software handles the config files is a bit more complicated than I explained in the original post. It uses inotify to monitor for changes in the config files. If an updated config file contains different values than what the user originally had, the software will detect that and give the user the option to restore their previous settings in the updated config file. The installer script is just to automate the process that I had already been doing manually.

    – Blackwood
    Sep 18 '17 at 14:49





















  • I would recommend man rsync and reading the options that pertain to links. Specifically, the --safe-links flag: "This tells rsync to ignore any symbolic links which point outside the copied tree." Or, perhaps the --no-OPTION option that enables you to do things like --no-links

    – h3rrmiller
    Sep 14 '17 at 15:18













  • I read about the --safe-links flag but that one didn't work for my scenario. Apparently I missed the --no-links option though. It does exactly what I need.

    – Blackwood
    Sep 14 '17 at 15:52











  • It's an easy one to miss since it's --no-OPTION to omit whatever OPTION is

    – h3rrmiller
    Sep 14 '17 at 16:29











  • What if the user customized the symlinks and config file contents? Updating an installation to a new version while preserving local config customization isn't something you can just whip up with some rsync/tar/cpio/find combo.

    – Kaz
    Sep 15 '17 at 3:30













  • Updating the config files should be rare (only when additional settings are added). However, the way the software handles the config files is a bit more complicated than I explained in the original post. It uses inotify to monitor for changes in the config files. If an updated config file contains different values than what the user originally had, the software will detect that and give the user the option to restore their previous settings in the updated config file. The installer script is just to automate the process that I had already been doing manually.

    – Blackwood
    Sep 18 '17 at 14:49



















I would recommend man rsync and reading the options that pertain to links. Specifically, the --safe-links flag: "This tells rsync to ignore any symbolic links which point outside the copied tree." Or, perhaps the --no-OPTION option that enables you to do things like --no-links

– h3rrmiller
Sep 14 '17 at 15:18







I would recommend man rsync and reading the options that pertain to links. Specifically, the --safe-links flag: "This tells rsync to ignore any symbolic links which point outside the copied tree." Or, perhaps the --no-OPTION option that enables you to do things like --no-links

– h3rrmiller
Sep 14 '17 at 15:18















I read about the --safe-links flag but that one didn't work for my scenario. Apparently I missed the --no-links option though. It does exactly what I need.

– Blackwood
Sep 14 '17 at 15:52





I read about the --safe-links flag but that one didn't work for my scenario. Apparently I missed the --no-links option though. It does exactly what I need.

– Blackwood
Sep 14 '17 at 15:52













It's an easy one to miss since it's --no-OPTION to omit whatever OPTION is

– h3rrmiller
Sep 14 '17 at 16:29





It's an easy one to miss since it's --no-OPTION to omit whatever OPTION is

– h3rrmiller
Sep 14 '17 at 16:29













What if the user customized the symlinks and config file contents? Updating an installation to a new version while preserving local config customization isn't something you can just whip up with some rsync/tar/cpio/find combo.

– Kaz
Sep 15 '17 at 3:30







What if the user customized the symlinks and config file contents? Updating an installation to a new version while preserving local config customization isn't something you can just whip up with some rsync/tar/cpio/find combo.

– Kaz
Sep 15 '17 at 3:30















Updating the config files should be rare (only when additional settings are added). However, the way the software handles the config files is a bit more complicated than I explained in the original post. It uses inotify to monitor for changes in the config files. If an updated config file contains different values than what the user originally had, the software will detect that and give the user the option to restore their previous settings in the updated config file. The installer script is just to automate the process that I had already been doing manually.

– Blackwood
Sep 18 '17 at 14:49







Updating the config files should be rare (only when additional settings are added). However, the way the software handles the config files is a bit more complicated than I explained in the original post. It uses inotify to monitor for changes in the config files. If an updated config file contains different values than what the user originally had, the software will detect that and give the user the option to restore their previous settings in the updated config file. The installer script is just to automate the process that I had already been doing manually.

– Blackwood
Sep 18 '17 at 14:49












2 Answers
2






active

oldest

votes


















1














Moved from question into answer:



As h3rrmiller pointed out, I was able to achieve this with rsync by using the --no-links option.






share|improve this answer

































    0














    According to the documentation of the cp command, you can use -d option:




    ‘-d’



    Copy symbolic links as symbolic links rather than copying the files that they point to, and preserve hard links between source files in the copies. Equivalent to --no-dereference --preserve=links.







    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%2f392236%2fhow-can-i-copy-a-directory-structure-but-ignore-symlinks%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      Moved from question into answer:



      As h3rrmiller pointed out, I was able to achieve this with rsync by using the --no-links option.






      share|improve this answer






























        1














        Moved from question into answer:



        As h3rrmiller pointed out, I was able to achieve this with rsync by using the --no-links option.






        share|improve this answer




























          1












          1








          1







          Moved from question into answer:



          As h3rrmiller pointed out, I was able to achieve this with rsync by using the --no-links option.






          share|improve this answer















          Moved from question into answer:



          As h3rrmiller pointed out, I was able to achieve this with rsync by using the --no-links option.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          answered Sep 18 '17 at 17:25


























          community wiki





          roaima


























              0














              According to the documentation of the cp command, you can use -d option:




              ‘-d’



              Copy symbolic links as symbolic links rather than copying the files that they point to, and preserve hard links between source files in the copies. Equivalent to --no-dereference --preserve=links.







              share|improve this answer






























                0














                According to the documentation of the cp command, you can use -d option:




                ‘-d’



                Copy symbolic links as symbolic links rather than copying the files that they point to, and preserve hard links between source files in the copies. Equivalent to --no-dereference --preserve=links.







                share|improve this answer




























                  0












                  0








                  0







                  According to the documentation of the cp command, you can use -d option:




                  ‘-d’



                  Copy symbolic links as symbolic links rather than copying the files that they point to, and preserve hard links between source files in the copies. Equivalent to --no-dereference --preserve=links.







                  share|improve this answer















                  According to the documentation of the cp command, you can use -d option:




                  ‘-d’



                  Copy symbolic links as symbolic links rather than copying the files that they point to, and preserve hard links between source files in the copies. Equivalent to --no-dereference --preserve=links.








                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 23 at 8:22









                  Stephen Kitt

                  169k24382458




                  169k24382458










                  answered Jan 23 at 7:19









                  Aboozar GhaffariAboozar Ghaffari

                  1




                  1






























                      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%2f392236%2fhow-can-i-copy-a-directory-structure-but-ignore-symlinks%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

                      How to make a Squid Proxy server?

                      Is this a new Fibonacci Identity?

                      19世紀