3

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.

kwallbmoc
  • 35
  • 2
  • 4
  • Could you just do `ln -s /var/www/yyy /var/www/xxx`? – staticsan May 16 '11 at 05:01
  • Still a no go. I want the actual files contained in /xxx to be linked in /yyy so when I pull up a webpage in my browser that loads from /yyy the necessary config.php files pertaining to that site can be along side the backend files from /xxx. – kwallbmoc May 16 '11 at 05:07

2 Answers2

5

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.

staticsan
  • 29,935
  • 4
  • 60
  • 73
  • Absolutely wonderful. This will hold ee over until I can get around to sprucing up my framework based on your suggestion. Much thanks. – kwallbmoc May 16 '11 at 05:19
  • I have forders, too, so if I try to do `cd /opt/xxx/f1` (because I wanted to put it in `/opt/`) I am getting `Too many levels of symbolic links`, any more suggestions? – sop Dec 08 '14 at 09:38
0

Just use ln -s /var/www/xxx/* /var/www/yyy

This tells ln: create a symlink for each file in xxx in the folder yyy. No need for for loops.

Jens Timmerman
  • 9,316
  • 1
  • 42
  • 48