Symlink all files in a directory with the entire directory tree
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
add a comment |
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
gcp -as
(only works with absolute paths though).
– Stéphane Chazelas
Dec 1 '14 at 11:08
add a comment |
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
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
osx symlink ln
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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 {} +
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
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%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
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 {} +
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
add a comment |
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 {} +
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
add a comment |
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 {} +
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 {} +
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
add a comment |
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
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%2f170813%2fsymlink-all-files-in-a-directory-with-the-entire-directory-tree%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
gcp -as
(only works with absolute paths though).– Stéphane Chazelas
Dec 1 '14 at 11:08