how to recursively symlink every file in a dir

Garance A Drosehn gad at
Thu Sep 9 20:29:28 UTC 2010

At 1:24 PM -0400 9/9/10, Aryeh Friedman wrote:
>I want to make it so every file is a seperate symlink in dir2 if and
>only if it is a regular file (not a dir) in dir1... the reason is if
>the file is unchanged then use symlink but I can rm the symlink and
>replace it with a non-symlink:
>To show the problem I am attempting to solve:
>foo: (owned by fred)
>     arf:
>        ack
>in barney's account:
>ln -s ~foo/ foo
>rm foo/arf/ack    # Permissioin denied ... it should nuke the symlink
>and let me then do something like "touch foo/arf/ack
>Note there are over 500 files upto 5 dirs deep in the dir I want to
>symlink from.... the final application is our version control system
>(devel/aegis) keeps seperate repos for different source code projects
>(for obvious reasons) and we want to make it so in normal operation we
>can symlink tne source tree from one project into an other but if we
>want to make a local modificiation to the "foreign" source tree all we
>have do is (sorry for the aegis commands but I think the idea is

I believe early X11-distributions had a script called "lndir"
would pretty much do exactly what you want here.  And then
there was a companion command called "breakln" which would
remove the symlink and make a copy of the original file to
replace it.

I don't know if X11 still has these commands (I haven't
installed X11 in at least 10 years), but I have my own
versions of them.  Let me know if you can't find them, and
I'll send you copies of my scripts.

(actually, I'm not 100% sure I got these from X11.  But I got
them from somewhere in the mid-1990's)

Garance Alistair Drosehn     =               drosehn at
Senior Systems Programmer               or   gad at
Rensselaer Polytechnic Institute;             Troy, NY;  USA

More information about the freebsd-questions mailing list