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.

  • 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
    Commented Sep 14, 2017 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
    Commented Sep 14, 2017 at 15:52
  • It's an easy one to miss since it's --no-OPTION to omit whatever OPTION is
    – h3rrmiller
    Commented Sep 14, 2017 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
    Commented Sep 15, 2017 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
    Commented Sep 18, 2017 at 14:49

2 Answers 2


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


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.


Moved from question into answer:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .