I would like to make an exact copy of a directory (which contains sub-directories, files, and symlinks) except that I want each file in the target directory to be a symlink back to the original file.
This I can already accomplish using:
cp -sR /home/me/SourceDir TargetDir
However, I would like any relative symlinks within SourceDir that point to somewhere else in SourceDir to remain the same relative links, hence now pointing to TargetDir.
For example, let's say SourceDir contains the following:
File0 Dir1/File1 Dir1/File2 Dir2/File3 Dir2/File2 <-- this is a symlink to ../Dir1/File2
Then I would like TargetDir to look like:
File0 <-- symlink to ../SourceDir/File0 Dir1/File1 <-- symlink to ../../SourceDir/Dir1/File1 Dir1/File2 <-- symlink to ../../SourceDir/Dir1/File2 Dir2/File3 <-- symlink to ../../SourceDir/Dir2/File3 Dir2/File2 <-- this is still a symlink to ../Dir1/File2, so: TargetDir/Dir1/File2
I wouldn't mind if this had to be accomplished in two or three steps (something I could write into a simple shell script).
One thought I had was first copying all symlinks only, then doing the cp -sR with a no-clobber.