Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

symlink real world example

Tags:

php

I was reading php functions and I came across symlink but I really couldnt grab it specially its usage in real world application developement. Can anybody please explain me with real world example?

Thanks

like image 552
Ayaz Alavi Avatar asked Feb 21 '11 08:02

Ayaz Alavi


2 Answers

Let's assume you have a src folder in your $HOME directory where your sources are stored. When you open a new shell, you usually enter your $HOME directory when the shell was started. It might be a common step that whenever you open up a new shell, you want to enter the directory ~/src/very_long_project_name afterwards.

This is where symlinks come into play: you could create a symlink in your $HOME directory (for example called vlpn that directly points to ~/src/very_long_project_name.

When you open your console next time, you could simply type cd vlpn instead of cd src/very_long_project_name. That's it. Nothing PHP specific. Like giraff and gnur already said.

like image 145
eckes Avatar answered Oct 13 '22 23:10

eckes


An administrator may create symlinks to arrange storage without messing up filesystems; e.g. a web mirror may have thousands of sites hosted, and dozens of disks mounted:

/mnt/disk1/
/mnt/disk2/
...

and want to store data in their /var/www/htdocs/ without users caring about which disk holds their data.

/var/www/htdocs/debian -> /mnt/disk1/debian
/var/www/htdocs/ubuntu -> /mnt/disk2/ubuntu
/var/www/htdocs/centos -> /mnt/disk9/centos

Second, you may have a 'latest upload'; your users are uploading photos, or software packages, and you want http://example.com/HOT_STUFF to always be the most recent uploaded photo. You could set the symlink($new_upload, $HOT_STUFF); and users will never need more than the one URL to see the newest thing.

Third, Debian and Ubuntu use the update-alternatives mechanism to allow multiple versions of a tool to be installed at once and yet still allow the administrator to say which one is the default. e.g.,

$ ls -l /usr/bin/vi
lrwxrwxrwx 1 root root 20 2011-01-11 01:07 /usr/bin/vi -> /etc/alternatives/vi
$ ls -l /etc/alternatives/vi
lrwxrwxrwx 1 root root 18 2011-01-11 01:07 /etc/alternatives/vi -> /usr/bin/vim.basic
$ ls -l /usr/bin/vim.basic
-rwxr-xr-x 1 root root 1866904 2010-09-28 04:06 /usr/bin/vim.basic

It's a little circuitous, but the configuration is maintained in a per-system /etc/ directory, and the usual /usr/bin/vi path will execute something that is very much like vi, when there are many choices available (nvi, elvis, vim, AT&T vi, etc.)

like image 39
sarnold Avatar answered Oct 13 '22 21:10

sarnold