Welcome to Dream.In.Code
Getting Help is Easy!

Join 107,708 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,131 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Creating a symbolic link

 
Reply to this topicStart new topic

> Creating a symbolic link, Creating a symbolic link on the Linux Operating System

no2pencil
Group Icon



post 2 Aug, 2007 - 09:40 PM
Post #1


What I will show you here is how to create a symbolic link on a Linux system. If you are not familiar with the Linux Operating System, you'll quickly notice that this is much more complex than the Windows simple 'network drive' usage. This method can be used to create links in & out of directories all across the File System! It's important to watch your permissions & access rights when creating your link.

It's usage is as follows:
CODE

ln [-Ffhinsv] source_file [target_file]


1st, lets show our current directory
CODE

$ pwd
/usr/home/user


Now we'll show that there is no temp directory.
CODE

$ ls -l temp
total 0


So let’s create one, & then display it.
CODE

$ mkdir temp
$ ls -l | grep temp
drwxr-xr-x  2 user  user      512 Aug  2 23:08 temp


Again, let’s show that there is no directory named temp2.
CODE

$ ls -l | grep temp2
$


Here we will create a symbolic link from temp to a new directory link2. Keep in mind, we never created a directory actually named temp2!
CODE

$ ln -s temp temp2
$ ls -l | grep temp2
lrwxr-xr-x  1 user  user        4 Aug  2 23:11 temp2 -> temp


Now that we have our symbolic link created, let’s echo some junk into a text file inside of our temp directory. Once we're done with that, we'll display the contents just to show it was created as intended.
CODE

$ echo junk > temp/junk.txt
$ cat temp2/junk.txt
junk


Here you will see the contents of the temp directory & then the temp2 directory, a link to the temp directory.
CODE

$ ls -l temp
total 2
-rw-r--r--  1 user  user  5 Aug  2 23:13 junk.txt
$ ls -l temp2
lrwxr-xr-x  1 user  user  4 Aug  2 23:13 temp2 -> temp


Once we're inside of the temp2 directory, we'll issue an ls showing the junk.txt text file that we created inside of temp.
CODE

$ cd temp2
$ ls
junk.txt


As you can see, once the symbolic link has been created it can be used in reference to the original temp directory. It is important to keep in mind that is simply a similar reference & not a copy! So if you remove anything inside of it, it WILL be removed from them both!
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!

jyno1
*



post 18 Jul, 2008 - 06:32 PM
Post #2
Hi,

How to create a symbolic link between directories in different servers?

My ecommance software that is uploaded to a secure SSL server needs to access to certain files in a directory in a non-secure server which has a totally different IP address. How could I create a symbolic link between, a directory "/user/htdocs/acatalog/" in 123.123.123.123 and a directory "/htdocs/acatalog/" in 111.111.111.111? The user name and passwords are different for both servers.

Many thanks,

JY
Go to the top of the page
+Quote Post

no2pencil
Group Icon



post 27 Jul, 2008 - 01:43 AM
Post #3
In order to have a link between clients, there must be software running that offers connections to the file system of that computer/server. Samba is good (& very popular) example of such a service.
Go to the top of the page
+Quote Post

Tom9729
Group Icon



post 31 Jul, 2008 - 06:17 PM
Post #4
Symbolic links working over TCP/IP would be..interesting.

Edit: Create a NFS share with the files that need to be accessed remotely.

Symbolic links being accessed on a mounted drive will not work correctly! They will likely end up pointing at your local filesystem!

This post has been edited by Tom9729: 31 Jul, 2008 - 06:19 PM
Go to the top of the page
+Quote Post


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 8/30/08 02:51AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month