Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to perform what rsync does (compiles many directories into a single directory) - But instead of copying files/sub-directories I need it to create a directory with symlinks that point to the original files/sub-directories.

share|improve this question
up vote 4 down vote accepted

Your question is ambiguous.

cp -l "$SRCDIR"/* "$DESTDIR"

find "$SRCDIR" -mindepth 1 \( -type d -printf 'mkdir "$DESTDIR/%P"\n' \) -o \
  \( -printf 'cp -l "%p" "$DESTDIR/%P"\n' \) | DESTDIR="$DESTDIR" bash

The first creates symlinks to the various items directly in $SRCDIR. The second recreates the directory structure and creates symlinks to the non-directories.

share|improve this answer
note also that cp -l makes hard links, whereas cp -s makes symlinks. If the tree is large and the 2nd option ends up being at all slow, it could also be accomplished with something along the lines of: for i in $(cd srcdir; find . -mindepth 1 -type d -printf '"%p" '); do mkdir -p "dstdir/${i}"; cp -l $(find "srcdir/${i}" -maxdepth 1 -not -type d -printf '"%p" ') "dstdir/${i}". – Brian Vandenberg Apr 29 '15 at 21:39
Two things I left out: 1) cp -s is only able to do relative symlinks if copying into the same directory, and 2) the cp command in my modification requires an eval. – Brian Vandenberg Apr 29 '15 at 21:48

You must log in to answer this question.

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