how to recursively symlink every file in a dir

Garance A Drosehn gad at
Fri Sep 10 00:23:59 UTC 2010

At 2:54 PM -0600 9/9/10, Chad Perrin wrote:
>On Thu, Sep 09, 2010 at 04:28:59PM -0400, Garance A Drosehn wrote:
>>  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.
>lndir is in ports:
>     > pkgsearch lndir
>     /usr/ports/devel/lndir
>I'm not so sure about a "breakln" being anywhere accessible,
>other than whatever tools you have handy.

>I'd like to see what you have, even if the OP doesn't need
>them.  Are they of your own making, or copied from somewhere?

It looks like my 'lndir' script started out as a copy of a
script named '' that the XConsortium had in Oct 1988.
Over the years I added a number of features to it.  Looking
at the 'lndir' which is installed by the port, it seems to
have added some of those same features, but my script writes
out it's progress in a nicer format (IMO).

Given that the port is written in C and much more recent, I
suspect it is the right way to go.  For large directories it
is much faster than my script.  I should check to see how
much work it'd be to add my formatting to the C version.

The 'breakln' script might be something written here at RPI.
Looks like the last change to it was done in 1993.  It is
pretty simple:

#  All the arguments are turned into copies of themselves,
#  and write access is granted to the user.    This is good
#  for making exceptions to trees built with lndir.
if [ $# = 0 ]; then
   echo "Usage: $0 files..."

for f in $* ; do
   mv $f $f.tmpln
   cp -p $f.tmpln $f
   rm $f.tmpln
   chmod u+w $f

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