Full Version: Creating a symbolic link
Dream.In.Code > Programming Tutorials > Linux Tutorials
no2pencil
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!
jyno1
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
no2pencil
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.
Tom9729
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 is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.