Solved

What are sym links?

Posted on 2008-10-24
13
269 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
  • 6
  • 6
13 Comments
 
LVL 3

Assisted Solution

by:siranm
siranm earned 40 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 20

Assisted Solution

by:edster9999
edster9999 earned 85 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 20

Expert Comment

by:edster9999
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

INTRODUCTION The purpose of this document is to demonstrate the Installation and configuration, of the HP EVA 4400 SAN Storage. The name , IP and the WWN ID’s used here are not the real ones. ABOUT THE STORAGE For most of you reading this, you …
Learn about cloud computing and its benefits for small business owners.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now