how to recursively symlink every file in a dir

Joshua Isom jrisom at gmail.com
Thu Sep 9 18:13:21 UTC 2010


On 9/9/2010 12:24 PM, 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

This should give you at least a good start:

find foo/ \( -type d -exec mkdir -p copy/'{}' \; \) -o \( -type f -exec 
ln -s '{}' copy/'{}' \; \)

That'll copy directory foo into copy/foo and the rest is fine.  You'll 
have to tweak the rest as you need but it'll get you started.


More information about the freebsd-questions mailing list