How can I copy a directory structure but ignore symlinks?
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
|
show 1 more comment
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
I would recommendman rsyncand reading the options that pertain to links. Specifically, the--safe-linksflag: "This tells rsync to ignore any symbolic links which point outside the copied tree." Or, perhaps the--no-OPTIONoption that enables you to do things like--no-links
– h3rrmiller
Sep 14 '17 at 15:18
I read about the--safe-links flagbut that one didn't work for my scenario. Apparently I missed the--no-linksoption 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-OPTIONto omit whateverOPTIONis
– 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
|
show 1 more comment
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
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
bash shell-script shell
edited Sep 18 '17 at 17:26
roaima
44.2k555119
44.2k555119
asked Sep 14 '17 at 15:12
BlackwoodBlackwood
136
136
I would recommendman rsyncand reading the options that pertain to links. Specifically, the--safe-linksflag: "This tells rsync to ignore any symbolic links which point outside the copied tree." Or, perhaps the--no-OPTIONoption that enables you to do things like--no-links
– h3rrmiller
Sep 14 '17 at 15:18
I read about the--safe-links flagbut that one didn't work for my scenario. Apparently I missed the--no-linksoption 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-OPTIONto omit whateverOPTIONis
– 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
|
show 1 more comment
I would recommendman rsyncand reading the options that pertain to links. Specifically, the--safe-linksflag: "This tells rsync to ignore any symbolic links which point outside the copied tree." Or, perhaps the--no-OPTIONoption that enables you to do things like--no-links
– h3rrmiller
Sep 14 '17 at 15:18
I read about the--safe-links flagbut that one didn't work for my scenario. Apparently I missed the--no-linksoption 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-OPTIONto omit whateverOPTIONis
– 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
|
show 1 more comment
2 Answers
2
active
oldest
votes
Moved from question into answer:
As h3rrmiller pointed out, I was able to achieve this with rsync by using the --no-links option.
add a comment |
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Moved from question into answer:
As h3rrmiller pointed out, I was able to achieve this with rsync by using the --no-links option.
add a comment |
Moved from question into answer:
As h3rrmiller pointed out, I was able to achieve this with rsync by using the --no-links option.
add a comment |
Moved from question into answer:
As h3rrmiller pointed out, I was able to achieve this with rsync by using the --no-links option.
Moved from question into answer:
As h3rrmiller pointed out, I was able to achieve this with rsync by using the --no-links option.
answered Sep 18 '17 at 17:25
community wiki
roaima
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Jan 23 at 8:22
Stephen Kitt
169k24382458
169k24382458
answered Jan 23 at 7:19
Aboozar GhaffariAboozar Ghaffari
1
1
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
I would recommend
man rsyncand reading the options that pertain to links. Specifically, the--safe-linksflag: "This tells rsync to ignore any symbolic links which point outside the copied tree." Or, perhaps the--no-OPTIONoption that enables you to do things like--no-links– h3rrmiller
Sep 14 '17 at 15:18
I read about the
--safe-links flagbut that one didn't work for my scenario. Apparently I missed the--no-linksoption 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-OPTIONto omit whateverOPTIONis– 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