How do I create and remove a symbolic link?

I was fiddling around with symbolic links in my unix box and realised how cool they were. Basically symbolic links (or symlinks) create a virtual copy of the master file. This virtual copy has almost 100% of the master’s functionalities and characteristics (you’ll need to play around with the owner and file permissions sometimes though), and the really good thing about symlinks is that if you update the master files, your symlinks automatically get updated too!

Here’s the Code for Creating a Symbolic Link (Symlink)


For example:

ln -s /home/user/public_html ./user

This points a symbolic link “./user” to /home/user/public_html”. If you want to create symlinks to the directory’s contents instead, add an asterisk to the end, like so “directory/*”. That will tell Unix to create the symbolic links to point to everything contained in the folder.

Here’s the Code for Removing or Deleting a Symbolic Link (Symlink)

rm directory

You can also use unlink, like this:

unlink directory

One thing I’ve realised is that you shouldn’t leave a trailing slash, because that denotes that the target is a directory, and Unix will complain.

Leave a Reply

Your email address will not be published. Required fields are marked *