Search code examples
command-line-argumentssymlinklsln

Symbolic Links in Ubuntu Recursively link to files in one directory to another


After searching stackoverflow and Google for the past hour I thought I would ask. If the title does not make sense here is what I am looking to achieve.

/var/www/xxx/ 

Say there are files in this above directory.

/var/www/yyy/

I want the files found in directory xxx to be symbolically linked within directory yyy. I cannot figure out how to get the symbolic links to work as such:

/var/www/yyy/filefromfolderxxx.html

as opposed to what I keep getting:

/var/www/yyy/xxx/filefromfolderxxx.html

Any help would be greatly appreciated.


Solution

  • Try this:

    cd /var/www/xxx
    for a in * ; do ln -s /var/www/xxx/$a /var/www/yyy/$a ; done
    

    This will symlink all the files one-by-one.

    It's a bit messy, though. If you have multiple sites sitting on the same codebase but requiring different configuration files, you should really teach your framework how co-ordinate that for you. It's not really difficult, but does require more thinking than I can spare for this reply, I'm sorry.