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? ;-)
2 Answers
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.
-
Also my first attempt. Failed to get
cp
to create symlink forsource/some_deeper_dir/files
.– JokesterApr 2, 2013 at 16:29 -
5In 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 Nov 3, 2016 at 21:05
In case cp -rs
is not the answer you're looking for, lndir
might be the correct answer.
-
Handled perfectly deep subdirectories structures. Installed it on debian using
sudo apt-get install xutils-dev
Sep 3, 2019 at 12:29 -
-
The
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. Mar 15, 2022 at 15:08
/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?