78

I'm confused with how symbolic links work. I hope someone can guide me in the right direction.

I want to put a demo online from our software, which normally only runs locally on a Mac Mini. So I put all the files in the var/www from my Ubuntu 12.04 server installation.

There are a lot of hardcoded links in the software which point to /Applications/XAMPP/xamppfiles/htdocs/narrowcasting

Of course, I could change all these code on my html/php files in /var/www, but that would be quite annoying. I hope I can fix this by creating a symbolic link. For example, I have a directory called thumb in /var/www/thumb. The PHP code is trying to put an image in /Applications/XAMPP/xamppfiles/htdocs/narrowcasting/thumb.

Can anyone give me a tip how to achieve this with a symbolic link?

1
  • Could you please give the complete path of the place where you want to place the link and the destination file/folder? (thumb inside thumb?... it is not clear) Nov 8, 2012 at 22:12

3 Answers 3

132

use the ln command to do symbolic links.

 ln -s <real folder> <link folder>

in this example, you will create link folder that will actually contain what real folder have, and if you save something to link folder it will actually save it into real folder

You can verify the link with the command ls -l which will show an arrow to where the link points.

Note that the folder containing the link must exist, so you would have to create it first.

So in your situation, the commands that you are looking for are

sudo mkdir /Applications/XAMPP/xamppfiles/htdocs/narrowcasting

sudo ln -s /var/www/thumb /Applications/XAMPP/xamppfiles/htdocs/narrowcasting/thumb

Again, you can verify that the link was actually made with

ls -l /Applications/XAMPP/xamppfiles/htdocs/narrowcasting/thumb
4
  • Thanks for your help. I've thought about it again and I think the easiest is if I just place all my files in /Applications/XAMPP/xamppfiles/htdocs/narrowcasting. So for example my index.php will be in ....htdocs/narrowcasting/index.php. A symlink from /var/www/ to the narrowcasting folder should work for this right? I tried: 'sudo ln -s /Applications/XAMPP/xamppfiles/htdocs/narrowcasting /var/www' As far as I can understand if I now go to the domainname it should point me to the index.php in the narrowcasting folder. This is not working. Am I still not understanding it correctly? Nov 9, 2012 at 10:21
  • with that command, you are "mirroring" the contents of /var/www into narrowcasting, you can verify that the link was correctly made by doing "ls" into that directory and verifying that it contains the files you want. where do you have your real files now?
    – Sam
    Nov 9, 2012 at 17:24
  • whats the output of "ls -l /Applications/XAMPP/xamppfiles/htdocs/narrowcasting/" ?
    – Sam
    Nov 9, 2012 at 17:25
  • 2
    must specify the full PATH.
    – Benny
    Apr 14, 2017 at 18:58
13
ln -s [source_folder] [link_location]

This will create a link named like source folder, but you can rename the link. This way you can quickly switch content of folder. Useful for things like swapping git repos without reconfiguring IDE and build scripts.

1
  • Best explanation thanks. Here is an example: ln -s /mnt/c/projects ~/projects
    – Andrew
    Oct 8, 2017 at 14:03
2

if you want to create a SOFT or symbolic link from

/Applications/XAMPP/xamppfiles/htdocs/narrowcasting/link-file

to

/var/www/destination-file

yo do:

$ ln -s /var/www/destination-file /Applications/XAMPP/xamppfiles/htdocs/narrowcasting/link-file

Try to use absolute paths because if not, the paths should be writen not from your current directory but from the directory the link-file will be

1
  • 1
    The last point (Absolute path) did work for me... Thanks!!!
    – TalESid
    Nov 18, 2018 at 14:13

Not the answer you're looking for? Browse other questions tagged .