find(1) and symbolic links

Doug Gwyn <gwyn> gwyn at brl-tgr.ARPA
Mon Sep 2 19:07:26 AEST 1985


> > In all of the 4.2bsd implementations I know about (VAX, Sun, Apollo), find(1) is specifically arranged
> > to not follow symbolic links.  There are a couple of reasons for this:
> >     1) If you follow a symbolic link, it's hard to get back.  Going back to .. doesn't work; instead,
> >        find would have to explicitly keep a stack of the directories it had visited.  While this would
> >        work, it would require find to do a getwd(2) at every directory level, and getwd is pretty slow.
> 
> Why would it require find to do a getwd? The file spelling checker in Kernighan
> and Pike doesn't. All you have to do is build the directory stack on the fly.
> I always assumed find did this rather than depending on ..

Peter is right.  Indeed, most if not all of the utilities in the BRL UNIX
System V emulation for 4.2BSD now avoid doing chdir( ".." ) in order to
avoid problems with symbolic links.  Our SVR2 Bourne shell has been
modified so that "cd .." does what one might expect (trim off rightmost
piece of pathname from current working directory) rather than wander off
in a different direction than was used to enter the directory.  It is
initialized by "cd $HOME" in /usr/5lib/profile (our equivalent of
/etc/profile), to make sure that it thinks you are in the directory as
speicifed in /etc/passwd and not wherever /bin/pwd would say you are.



More information about the Comp.bugs.4bsd.ucb-fixes mailing list