Create symlinks recursively for a whole tree
19,051
Solution 1
cp -rs source/ dest/
should do the trick. The directory structure will be recreated at dest/ with each file being a symlink to its counterpart in source.
Solution 2
In case cp -rs
is not the answer you're looking for, lndir
might be the correct answer.
Related videos on Youtube
Author by
lzap
Updated on September 18, 2022Comments
-
lzap over 1 year
I am seeking for a command that would re-create a whole tree of files in a different directory. I would prefer to have all symlinks absolute. Can I do that with a find and xargs? ;-)
-
jankes over 12 yearsI don't get the idea. If you make, for example, a symlink named
/tmp/somedirectory
pointing at/home/me/somegreatdir
, then all the contents ofsomegreatdir
will be visible under/tmp/somedirectory
. This needs just one symlink for the entire tree. Or what else do you want? -
kaiya about 2 yearse.g. first synching the whole structure, but then remove some of them. There are applications for it.
-
-
Jokester about 11 yearsAlso my first attempt. Failed to get
cp
to create symlink forsource/some_deeper_dir/files
. -
22degrees over 7 yearsIn my experience, you have to use the full path to source (e.g.
cp -Rs /home/myusername/source dest
) otherwise it will complain. here's a ref: lists.gnu.org/archive/html/help-gnu-utils/2004-08/msg00039.html -
Guillaume Berche over 4 yearsHandled perfectly deep subdirectories structures. Installed it on debian using
sudo apt-get install xutils-dev
-
kaiya about 2 yearsPlease explain why.
-
Mikko Rantalainen about 2 yearsThe
lndir
can handle relative links correctly whereas at least older versions ofcp -rs
only supported absolute paths for the first argument. Thelndir
is officially meant for building X Server from source code so it's actually meant to be used for one specific purpose because (1)cp -rs
was not supported on all platforms and (2)cp -rs
didn't support relative path as the first argument.