Solved

What are sym links?

Posted on 2008-10-24
13
275 Views
Last Modified: 2010-04-19
Hi

Could somebody please explain what/how/why of symbolic links for Dummies please?
Thanks
0
Comment
Question by:Lady_M
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
13 Comments
 
LVL 3

Assisted Solution

by:siranm
siranm earned 40 total points
ID: 22795632
If translated to windows, symlinks (SYMbolic links) would be like  a 'direct access'.

That is, a 'file' that only points to another file.

There are two type, hard links and soft link.

A hard link is like having the same filecontents associated with two different names on you computer. It is the same which fileNAME you access.

A softlink is like an arrow (a file arrow) that just points to a file. Whenever you access the arrow, the system redirects you to the pointed file.

 
0
 
LVL 20

Accepted Solution

by:
edster9999 earned 85 total points
ID: 22795722
A symlink is a pointer or a redirection to another place.

image you have a set of folders in your own home area called
"work", "rest" and "play"

You decide to also have a music folder but there is already a general music folder outside for everyone to access.  You can put a symlink which will look like a 4th folder but will just point to the one outside your area.  This is better than copying the music folder as then there would be 2 copies taking up twice the space.

so now you look at your folders :
work, res, play and music

and if you ask for more details (with ls -l) you can see music is really outside
work
rest
play
music -> /public/music
0
 

Author Comment

by:Lady_M
ID: 22795861
Thanks guys.

edster9999 - ah now I get it.  So just like windows shortcuts?

So I need to do this on my host server.  I want to create sym links from two subdirectories to a folder in the root.  What are the steps?
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 20

Assisted Solution

by:edster9999
edster9999 earned 85 total points
ID: 22796071
Yes - similar (but more powerful)

if the folder in the root is called /music
and you wish this to appear inside
/home/boris
and
/home/jane

you type these commands

ln -s /music /home/boris/music
ln -s /music /home/jane/music

this will create a symlink folder called music inside both locations

you could even call it by a different name

ls -s /music /home/boris/my-tunes
0
 

Author Comment

by:Lady_M
ID: 22796250
And so suppose I want to create a link in the header of my file in the subdirectory to point to a file that is located in the directory in the root, I would just create a relative link to the one in the subdirectory - is that right?
0
 

Author Comment

by:Lady_M
ID: 22796315
I'm not sure I explained that very well, what I meant was:

Suppose I have a global stylesheet in the root called /global_stylesheets/main.css

And I want to link to it from a file in /subdirectory/pages/mypage.html

And I've got a sym link in my subdirectory such as /subdirectory/my_global_symlink

Then in the head of mypage.html I would put:

<head>
<link rel="stylesheet" href="../my_global_symlink/main.css" type="text/css" media="screen"/>
</head>

Is that right?
0
 
LVL 20

Expert Comment

by:edster9999
ID: 22796601
Totally different form of linking....

Up to now we have been talking about the file system.  Finding files and folders as you browse round the hard disks.

Here you are talking about find files in your web server.

It is a good idea to keep only one copy of files like this on a web server and certainly not a good idea to use sym links.  It will always lead to confusion later.

So lets use your example above.  and put it in a folder on the hard disk

/www/mainsite/

so the root of your web site is in /www/mainsite
and inside here you have a folder called global_stylesheets
abd one called /subdirectory/pages

in any file on this system you will just need to use the path /global......
as this is this relies on the root of this system.  Ignore symlinks here... in fact don't use them.

<link rel="stylesheet" href="/global_stylesheets/main.css" type="text/css" media="screen"/>

that will find the file form any folder or sub folder on that site.

0
 

Author Comment

by:Lady_M
ID: 22796714
Hi
That's what I originally tried but my host told me that wasn't possible.  The subdirectories I am talking about here are subdomains and it's not possible to traverse up the tree from them to the root with relative links, nor to reference files in the root as you've suggested, so they suggested symlinks to me as the only solution.
0
 
LVL 20

Assisted Solution

by:edster9999
edster9999 earned 85 total points
ID: 22796936
No sym links are bad in web site design and should be avoided.

so lets start the example again....

Do you have something like this

/www/mainsite/
/www/subsite/

and then each is referenced by a seperate web address
example top one is www.example.com
and the bottom on is london.example.com

Is that right ?

If so then it is correct that you can not access the files in the way I stated above as they are on different web sites (I did use the phrase "will find the file from any folder or sub folder on that site.")
As they are separate sites you have two options.

1. you can put in the full web site reference in the code and then it will pull the file from the other site.
So if the file is located in the top directory (www site) then from the bottom one (London site) you can have the code :

<link rel="stylesheet" href="http://www.example.com/global_stylesheets/main.css" type="text/css" media="screen"/>

and this would pull the file off the other server.

2. Copy the files.  This is cleaner and would not result in any problems if you took the top site down or renamed it but would mean 2 copies of the file to maintain.
One in each folder
0
 

Author Comment

by:Lady_M
ID: 22796996
No the structure is like this:

www.mytopdomain.com
www.mysubdomain.com
www.myothersubdomain.com

But the folders look like this:

public_html/mytopdomain/mysubdomain/
public_html/mytopdomain/myothersubdomain/

So I want to put a global folder in public_html/global_files/

and reference them from public_html/mytopdomain/
and
public_html/mytopdomain/mysubdomain/

0
 
LVL 20

Expert Comment

by:edster9999
ID: 22797161
a server can not go above its root area so you can not use ".." as above in your examples and you can not refence anything in public_html as it is above the root.

The options 1 and 2 a couple of messages up still stand as valid in this situation.
0
 

Author Comment

by:Lady_M
ID: 22797450
Ah okay, I assumed that the root was the level above /public_html/.  But it's actually /mytopdomain/

?

Thanks for your help.
0
 
LVL 20

Expert Comment

by:edster9999
ID: 22797709
in the configuration for the individual web site you specify the root folder.
You could set it to be /public_html but you would then be looking for the files in this folder and if the site was inside /mytopdomain/ you would have to have that in the web address for all those files.

root folder is what you get into when you do just

http://www.mytopdomain.com/
0

Featured Post

Save the day with this special offer from ATEN!

Save 30% on the CV211 using promo code EXPERTS30 now through April 30th. The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Requirements: root access via SSH, telnet, or other.. Alternately, access from the server administrator to run a counter-strike server, and the proper access rights to do so. Enough free disk space (and allowed to use this much, eg disk quota): 6…
Moving your enterprise fax infrastructure from in-house fax machines and servers to the cloud makes sense — from both an efficiency and productivity standpoint. But does migrating to a cloud fax solution mean you will no longer be able to send or re…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question