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? ;-)

  • 1
    I don't get the idea. If you make, for example, a symlink named /tmp/somedirectory pointing at /home/me/somegreatdir, then all the contents of somegreatdir will be visible under /tmp/somedirectory. This needs just one symlink for the entire tree. Or what else do you want?
    – jankes
    Nov 12, 2011 at 23:41
  • 1
    e.g. first synching the whole structure, but then remove some of them. There are applications for it.
    – kaiya
    Mar 15, 2022 at 10:04
  • @jankes, as another example, think of a read-only filesystem you want to use as a cache, but where you might want to add additional files (to your local copy, since you can't modify the original). May 6, 2022 at 19:56

2 Answers 2


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.


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
  • Please explain why.
    – kaiya
    Mar 15, 2022 at 10:05
  • The lndir can handle relative links correctly whereas at least older versions of cp -rs only supported absolute paths for the first argument. The lndir 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .