Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recursively symlink directory tree

I'm trying to run a recursive symlink from one directory into another:

find data/* -type d -exec ln -s {} current/{} \;

With one addition: I need to strip off data/ from the prefix.

Running on OS X server (10.8, Mountain Lion)--not all standard GNU commands, like cp -rs, are supported.

What I mean by recursively:

data is a list of persistent directories between Laravel releases:

data/
    \ storage/
        - framework/
            - session/
        - app/
        \ logs/

They need to map to:

current/
    \ storage/
        - framework
            - session/
        - app/
        - logs/
      # Also in storage, but we do NOT want to persist
        - debugbar/
        - framework/
            - cache/
            - views/

Our data directory is will be persistent storage between application launches, as we update our site, while retaining previous versions of the site in the event of rollbacks (current happens to be a softlink to the latest release).

Note: we also have other sites other than Laravel. data is going to be our standard, and we're going to match directory restructure depending on what the site requires for persistence. It won't always be data/storage.

like image 676
guice Avatar asked Sep 19 '25 12:09

guice


1 Answers

You don't need to do any recursion. Once you've linked to a directory, all of the files and directories under it are accessible through the link.

The only links you need are to the directories at the top level…

cd current
ln -s ../data/*/ .

Or, depending on your requirements, making current a link to data might even be sufficient.