Symbolic links to directories are handy tools to have on your Linux server. One thing you can do with them is share a folder of resources with many different sites on your server. Unfortunately, they are a little tricky to create or move around. Most tools like CPanel or FTP choke a little on symbolic links. So this means you have to use command line. I am writing this post for three primary reasons:
- I found a bit of misinformation online.
- This is a reminder to myself of what I learned in case I forget four years from now.
- Hopefully, someone else will find this information useful, too.
As we used to joke in the days of DOS, who needs fancy operating systems? What could be simpler than telling your computer what you want it to do one line at a time. On Mac, you can pretend your a Linux geek and SSH right into your Linux server and command-line away.
Let’s look at how you can create symbolic links to directories in just five steps.
Step 1: Open Terminal
If you don’t know where it is, do a search. The terminal application on OS X is a fun little tool with preferences that allow you to customize the look and feel and even add a background image. This is what mine looks like.
Step 2: Get Logged into Your Server
ssh -p 2222 YOUR-USER-NAME@YOUR-IP-ADDRESS
(Replace the command above with your user name and your actual IP address.)
You will be prompted for a password. You may be able to paste it in, but you may have to type it. On my server, it did not show me any feedback as I typed.
Step 3: Be Careful
Terminal is one of those unforgiving computer interfaces where typing the wrong thing can wipe out an entire directory or drive in a few seconds.
Step 4: Create Your Symbolic Link
ln -s ~/path/your/linking/to ~/path/where/you/want/the/link/file
In my case I was using this:
ln -s ~/samples ~/site
This created a symbolic link called “samples” inside of my “site” folder.
If I had done this instead:
ln -s ~/samples ~/site/elearningsamples
If there was not a directory called “elearningsamples” it would create a link called “elearningsamples” inside of my site folder that pointed to the “samples” folder.
If there was a folder named “learningsamples” it would create the “samples” symbolic link inside of that folder.
Step 5: Enjoy Not Having to Maintain Duplicate Folders
You are now a symbolic link master. You can also create symbolic links to individual files, but I have never found much use for that. Why link to a file when you can link to a whole folder of files?
Written by Tim Bobo
More About Symbolic Links
- Understanding Linux Links – Jack Wallen
If you have thoughts to add on this topic, contact us.