Symlink all files in a directory with the entire directory tree












1















Right now I use this



ln -s /dir/* /dir2/


Which will symlink everything, but I have to go inside the dir and make a new directory because the folders are also symlinked (this is expected).



So here is what Im trying to achieve: Symlink all files, but when there is a folder, make a directory with the same name and symlink the files inside of that folder and inside that folder, etc.



Much like GNU cp with the -al flag, which I got by running brew install coreutils.



gcp -al /dir1/ dir2/ 


This does what I want except they are hard links and not symlinks.










share|improve this question























  • gcp -as (only works with absolute paths though).

    – Stéphane Chazelas
    Dec 1 '14 at 11:08
















1















Right now I use this



ln -s /dir/* /dir2/


Which will symlink everything, but I have to go inside the dir and make a new directory because the folders are also symlinked (this is expected).



So here is what Im trying to achieve: Symlink all files, but when there is a folder, make a directory with the same name and symlink the files inside of that folder and inside that folder, etc.



Much like GNU cp with the -al flag, which I got by running brew install coreutils.



gcp -al /dir1/ dir2/ 


This does what I want except they are hard links and not symlinks.










share|improve this question























  • gcp -as (only works with absolute paths though).

    – Stéphane Chazelas
    Dec 1 '14 at 11:08














1












1








1








Right now I use this



ln -s /dir/* /dir2/


Which will symlink everything, but I have to go inside the dir and make a new directory because the folders are also symlinked (this is expected).



So here is what Im trying to achieve: Symlink all files, but when there is a folder, make a directory with the same name and symlink the files inside of that folder and inside that folder, etc.



Much like GNU cp with the -al flag, which I got by running brew install coreutils.



gcp -al /dir1/ dir2/ 


This does what I want except they are hard links and not symlinks.










share|improve this question














Right now I use this



ln -s /dir/* /dir2/


Which will symlink everything, but I have to go inside the dir and make a new directory because the folders are also symlinked (this is expected).



So here is what Im trying to achieve: Symlink all files, but when there is a folder, make a directory with the same name and symlink the files inside of that folder and inside that folder, etc.



Much like GNU cp with the -al flag, which I got by running brew install coreutils.



gcp -al /dir1/ dir2/ 


This does what I want except they are hard links and not symlinks.







osx symlink ln






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 1 '14 at 10:28









DisplayNameDisplayName

4,44894580




4,44894580













  • gcp -as (only works with absolute paths though).

    – Stéphane Chazelas
    Dec 1 '14 at 11:08



















  • gcp -as (only works with absolute paths though).

    – Stéphane Chazelas
    Dec 1 '14 at 11:08

















gcp -as (only works with absolute paths though).

– Stéphane Chazelas
Dec 1 '14 at 11:08





gcp -as (only works with absolute paths though).

– Stéphane Chazelas
Dec 1 '14 at 11:08










1 Answer
1






active

oldest

votes


















0














I guess you should separate the file handling from the directory handling. Make the directories first. In the GNU world:



cd /dir2
find /dir -mindepth 1 -maxdepth 1 -type d -exec mkdir {} ;


And then the symlinks:



find /dir -mindepth 1 -maxdepth 1 -type f -exec ln -s -t /dir2 {} +





share|improve this answer
























  • Drop -maxdepth 1 since the copy should recurse. mkdir {} is wrong: you're attempting to create directories that already exist. You need to translate /dir into /dir2 in the paths.

    – Gilles
    Dec 2 '14 at 14:29











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%2f170813%2fsymlink-all-files-in-a-directory-with-the-entire-directory-tree%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I guess you should separate the file handling from the directory handling. Make the directories first. In the GNU world:



cd /dir2
find /dir -mindepth 1 -maxdepth 1 -type d -exec mkdir {} ;


And then the symlinks:



find /dir -mindepth 1 -maxdepth 1 -type f -exec ln -s -t /dir2 {} +





share|improve this answer
























  • Drop -maxdepth 1 since the copy should recurse. mkdir {} is wrong: you're attempting to create directories that already exist. You need to translate /dir into /dir2 in the paths.

    – Gilles
    Dec 2 '14 at 14:29
















0














I guess you should separate the file handling from the directory handling. Make the directories first. In the GNU world:



cd /dir2
find /dir -mindepth 1 -maxdepth 1 -type d -exec mkdir {} ;


And then the symlinks:



find /dir -mindepth 1 -maxdepth 1 -type f -exec ln -s -t /dir2 {} +





share|improve this answer
























  • Drop -maxdepth 1 since the copy should recurse. mkdir {} is wrong: you're attempting to create directories that already exist. You need to translate /dir into /dir2 in the paths.

    – Gilles
    Dec 2 '14 at 14:29














0












0








0







I guess you should separate the file handling from the directory handling. Make the directories first. In the GNU world:



cd /dir2
find /dir -mindepth 1 -maxdepth 1 -type d -exec mkdir {} ;


And then the symlinks:



find /dir -mindepth 1 -maxdepth 1 -type f -exec ln -s -t /dir2 {} +





share|improve this answer













I guess you should separate the file handling from the directory handling. Make the directories first. In the GNU world:



cd /dir2
find /dir -mindepth 1 -maxdepth 1 -type d -exec mkdir {} ;


And then the symlinks:



find /dir -mindepth 1 -maxdepth 1 -type f -exec ln -s -t /dir2 {} +






share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 1 '14 at 10:54









Hauke LagingHauke Laging

56.4k1285135




56.4k1285135













  • Drop -maxdepth 1 since the copy should recurse. mkdir {} is wrong: you're attempting to create directories that already exist. You need to translate /dir into /dir2 in the paths.

    – Gilles
    Dec 2 '14 at 14:29



















  • Drop -maxdepth 1 since the copy should recurse. mkdir {} is wrong: you're attempting to create directories that already exist. You need to translate /dir into /dir2 in the paths.

    – Gilles
    Dec 2 '14 at 14:29

















Drop -maxdepth 1 since the copy should recurse. mkdir {} is wrong: you're attempting to create directories that already exist. You need to translate /dir into /dir2 in the paths.

– Gilles
Dec 2 '14 at 14:29





Drop -maxdepth 1 since the copy should recurse. mkdir {} is wrong: you're attempting to create directories that already exist. You need to translate /dir into /dir2 in the paths.

– Gilles
Dec 2 '14 at 14:29


















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%2f170813%2fsymlink-all-files-in-a-directory-with-the-entire-directory-tree%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 reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

is 'sed' thread safe

How to make a Squid Proxy server?