Symbolically merging one directory into another
I found this technique necessary when working with vBulletin. I want to keep the core directory clean for easy upgrades (which often involves replacing the directory with the new release) and I don’t want to have to tediously copy files in each time. Solution: keep the files separate and recreate symbolic links on the fly.
# First remove any pre-existing links
find . -type l -print0 | xargs -0 rm;
# Then symbolically link dir2 into dir1
for file in `cd dir2; find`; do
if [ ! -e dir1/$file ]; then
depth=`echo $file | awk -F '/' '{print NF}'`;
prefix=`perl -e 'print "../"x$ARGV[0]' $depth`;
ln -s "$prefix"dir2/$file dir1/$file;
fi
done